[SOLVED]Getting a random led to blink, help needed for a newbie!

Hello!

I have red yellow and green leds connected to lilypad arduino ports 9,10 and 11.

When the pad is reset Id like a random led to start blinking. Nothing happens. What am I doing wrong? I have this programmed.

Thank You! =)

void loop(){ } int ranNum; int ranDel;

void setup() { // Setup 3 output ports for LED's pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT);

//Generate random number between 9 and 11 ranNum=random(9,11); //Turn on the LED digitalWrite(ranNum, HIGH); //Turn off the LED digitalWrite(ranNum, LOW); }

(deleted)

Hi!

Thanks for the answer!
If I write
delay(500);

is it then blinking slower?

If I write delay(500);

is it then blinking slower?

Not...if...the...only...place...you...write...it...is...on...the...forum.

The code is like this now. Everything working fine except this selects the same led (10) everytime. Did I write something wrong or am I just very lucky? =)

void loop(){ } int ranNum; int ranDel;

void setup() { // Setup 3 output ports for LED's pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT);

//Generate random number between 9 and 11 ranNum=random(9,12); //Turn on the LED digitalWrite(ranNum, HIGH); delay(500); //Turn off the LED digitalWrite(ranNum, LOW); delay(500); //Turn on the LED digitalWrite(ranNum, HIGH); delay(500); //Turn off the LED digitalWrite(ranNum, LOW); delay(500); }

I’m sorry guys but this is not actually my field at all…although I understand the basics, I really need some help! I study to be an elementary school teacher and we’ve got this course at uni where we’re supposed to get to know some future possibilities for schools and teaching. I can’t get this shit done!! So frustrating…

That's expected behaviour - from the reference:

If it is important for a sequence of values generated by random() to differ, on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin.

As it happens, using analogRead in this way isn't a particularly good source of randomness, but for the purposes of your exercise, it should do the trick.

As it happens, using analogRead in this way isn't a particularly good source of randomness, but for the purposes of your exercise, it should do the trick.

Moving the code to generate a random number and turn a pin on to loop() will also demonstrate that the process works.

Using randomSeed, with some unique input, will result in unique random numbers, and may prove useful in the future. But, get different lights working first.

PROBLEM SOLVED! thank you Everytime started, this gives me one answer, red yellow or green.

heres the code: maybe something extra there somewhere, but atleast it is working! Thank you very much! void loop(){} int ranNum; int analogPin2 = 2; int analogPin3 = 3;

void setup() { Serial.begin(9600); randomSeed(analogRead(0)); // Setup 3 output ports for LED's pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT);

//Generate random number between 9 and 11 ranNum=random(9,12); Serial.println(ranNum); //Turn on the LED digitalWrite(ranNum, HIGH); delay(500); //Turn off the LED digitalWrite(ranNum, LOW); delay(500); //Turn on the LED digitalWrite(ranNum, HIGH); delay(500); //Turn off the LED digitalWrite(ranNum, LOW); delay(500); }