Hi everyone, my question is simple-I have two LED-s hooked up to the arduino and I want them to light up one at a time, but without order.
I'm trying to make something like the SlamMan
Hi everyone, my question is simple-I have two LED-s hooked up to the arduino and I want them to light up one at a time, but without order.
I'm trying to make something like the SlamMan
You might be able to use one of the pins as an analog pin, have it be a floating pin (nothing attached) and read the value of that pin. Since it is floating, you might get a pretty random value, which you can then use to determine if you want the LEDs on or off, or use two pins for two "random" sources. It could also be that depending on how the analog to digital conversion works, this may not be useful at all, that is you might get 1 sudo-random read, and then 0 for the rest. Just a thought. Don't know if it would work.
this might work, but I want to add delay (one led lights up for 1sec, then the other one-for 1 sec...)
A quick google search gives me this code:
long randNumber;
void setup(){
Serial.begin(9600);
// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
}
void loop() {
// print a random number from 0 to 299
randNumber = random(300);
Serial.println(randNumber);
// print a random number from 10 to 19
randNumber = random(10, 20);
Serial.println(randNumber);
delay(50);
}
from http://www.arduino.cc/en/Reference/Random
You should be able to use that to easily rig up a randomiser for lighting LEDs..
A quick google search gives me this code:
long randNumber;
void setup(){
Serial.begin(9600);
// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
}
void loop() {
// print a random number from 0 to 299
randNumber = random(300);
Serial.println(randNumber);
// print a random number from 10 to 19
randNumber = random(10, 20);
Serial.println(randNumber);
delay(50);
}
from http://www.arduino.cc/en/Reference/Random
You should be able to use that to easily rig up a randomiser for lighting LEDs..
That's a much better idea.