Show Posts
Pages: 1 ... 30 31 [32] 33 34 ... 39
466  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Pseudo random function help on: June 15, 2010, 02:20:49 pm
Thanks AWOL.  I'll try that when I get home.

Never heard of a Fisher–Yates shuffle before, interesting...
467  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Pseudo random function help on: June 15, 2010, 11:34:17 am
Ok.  I think I get what Grumpy_Mike is saying.  I should randomize the list then just play the list.  Once the list is done randomize it again and then play it again.

Where I get fuzzy is here.

Quote
Then generate a pair of random numbers and use them as the index to swap the values in the array

So far I've got the code here.  This will generate a random list, but it being completely random I could get the same song 10 times in a row.
Code:
int mySongs[10]={0,1,2,3,4,5,6,7,8,9};

void RandomList()
{
      randomNumber=random(10);
    int i;
          for (i = 0; i < 10; i = i + 1)
            {
          songToPlay=random(10);
          mySongs[i] = songToPlay;
            }
}
468  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Pseudo random function help on: June 15, 2010, 10:49:36 am
Thanks for the help everyone.  I might find  arrays a little easier.  I'll let you know which solution I try.
469  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Pseudo random function help on: June 14, 2010, 11:23:28 am
Can anyone give me an example of a bit mask?
Ok, I found an example. Let me make sure I understand it.
Ignoring all the transmit stuff I want to convert this for part of my random fuction.

Where I get lost is here
Quote
else{ //if bitwise and resolves to false
      digitalWrite(transmit,LOW); // send 0
    }
In this section I would have a new random number that has not been picked.  How do I write that this has now been picked?
Say my new random number was 3.  How do I write that the number 3 has now been picked and not to pick it again?

Code:
byte transmit = 7; //define our transmit pin
byte data = 170; //value to transmit, binary 10101010
byte mask = 1; //our bitmask
byte bitDelay = 100;

void setup()
{
   pinMode(transmit,OUTPUT);
}

void loop()
{
  for (mask = 00000001; mask>0; mask <<= 1) { //iterate through bit mask
    if (data & mask){ // if bitwise AND resolves to true
      digitalWrite(transmit,HIGH); // send 1
    }
    else{ //if bitwise and resolves to false
      digitalWrite(transmit,LOW); // send 0
    }
    delayMicroseconds(bitDelay); //delay
  }
}
470  Forum 2005-2010 (read only) / Frequently-Asked Questions / Pseudo random function help on: June 14, 2010, 09:31:18 am
Hi,
I am using a WAVE Shield to play songs.
I want to play all 10 songs in a random order every time until it has played all 10, then start over.
I know there should be an easy solution to this, but am kind of stuck.
My code is below and as you can see, it doesn't do what I need so far.
How can I pick 10 items at random until all 10 are picked?
Thanks.

Code:
void randomizer()
{
       songNumber = random(10);

      if (songNumber == prevSong)
       {
                    songNumber = random(10);
       }
       prevSong = songNumber;
}
471  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Playing drum sound samples on: June 10, 2010, 03:49:21 pm
Try a Wave Shield from Adafruit to play wav files.
Your sound files are stored on an SD card.
http://www.adafruit.com/index.php?main_page=product_info&cPath=17_21&products_id=94&zenid=58cafcfbee5868485e423d4071b57e5f
472  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Power question Duemilanove & Waveshield on: May 31, 2010, 09:16:13 am
Thanks PaulS.  
473  Forum 2005-2010 (read only) / Frequently-Asked Questions / Power question Duemilanove & Waveshield on: May 31, 2010, 08:15:34 am
Noob question.
Can I run a Duemilanove and a Wave shield from 4 AA batteries?
This give me 6 volts.  I'm not sure how much current a Wave shield uses.
I have no way to test this without cutting some wire.

Thanks.
474  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Transistor Problem on: May 28, 2010, 03:24:42 pm
Nice sketch.  I have a setup just like your last sketch connected to a motion detector and 6 LEDS.
I notice if it is a PNP transistor pin 2 would either automatically be high or low and an NPN transistor  is the exact opposite.  I forget which one is which.
475  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Arduino Web Interface on: March 31, 2010, 11:17:39 am
Did you look at Asynclabs Yellowjacket or Black Widow?  These include an Arduino in them.  No need to buy an Arduino.
476  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Arduino Web Interface on: March 31, 2010, 10:53:52 am
The WiShield from Asynclabs works over wifi.
http://www.asynclabs.com/
477  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Electrical connections to a rotating part? on: May 25, 2010, 01:30:18 pm
How about a Hall Effect sensor and a magnet?
http://www.sparkfun.com/commerce/product_info.php?products_id=9312
I know, not exactly an electrical connection, but my bike computer seems to get a lot of info out of one.
478  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Best Way to Save Power on: May 19, 2010, 03:49:53 pm
I didn't delete any comments .  I'll have a longer look at the datasheet when I have more time.
But on first look that looks just as confusing.
479  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Best Way to Save Power on: May 19, 2010, 03:13:16 pm
In the Nightingale example I understand most of it, but can anyone explain the following.
Quote
cbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter OFF
sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON
In the void system_sleep() section , What does this do and why is it needed?

Also, I am a bit confused by the watchdog code.
Where do I set the time I want the watchdog to wait before waking up the Arduino?

Code:
void setup_watchdog(int ii) {

  byte bb;
  int ww;
  if (ii > 9 ) ii=9;
  bb=ii & 7;
  if (ii > 7) bb|= (1<<5);
  bb|= (1<<WDCE);
  ww=bb;
  Serial.println(ww);


  MCUSR &= ~(1<<WDRF);
  // start timed sequence
  WDTCSR |= (1<<WDCE) | (1<<WDE);
  // set new watchdog timeout value
  WDTCSR = bb;
  WDTCSR |= _BV(WDIE);


}
480  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Best Way to Save Power on: May 19, 2010, 08:45:36 am
Thanks.  That is very helpful.  Is there any way to make the Arduino sleep for a certain amount of time?
Or to wake it up without detecting something external to start an interrupt?
Pages: 1 ... 30 31 [32] 33 34 ... 39