Good Morning
I want to light 10 LEDs randomly. More specifically, turn on one LED at random, leave it on, then turn on a second LED at random, leave it on, and so forth until a line of 10 LEDs are all lit.
My circuit is an Arduino Uno with a ten segment bar-graph (DIP, NTE3115) connected to DigPins 4 thru 13, they are called LEDa thru LEDj.
I can get to 10 LEDs to light individually in a random pattern in a sketch that is an expanded version of Light Blink. The overall sketch is wordy and sloppy but it works well enough.
Any other tips would be appeciated.
Below is a the section of the sketch dealing with random blinking
while(count<300) //start Random_Pattern and run 300 times
{
if(randnum==1) //see if randnum is 1
{
digitalWrite(LEDa, HIGH); //if randnum is 1 turn on LEDa
delay (randelay); //leave LEDa on for random time
}
else
{
digitalWrite(LEDa, LOW); //if randnum is not 1 turn off LEDa
}
if(randnum==2) //see if randnum is 2
{
digitalWrite(LEDb, 1); //if randnum is 2 turn on LEDb /Same as HIGH/
delay (randelay); //leave LEDb on for random time
}
else
{
digitalWrite(LEDb, 0); //if randnum is not 2 turn LEDb off
}
// A LARGE SECTION OF THE SKETCH WAS OMMITED HERE TO KEEP THE FORUM POST SMALLER//
if(randnum==10){ //see if randnum is 10
digitalWrite(LEDj, 1); //if randnum is 10 turn LEDj on
delay(randelay); //keep LEDj on for random time
}
else{
digitalWrite(LEDj,0); //if randnum is not 10 turn LEDj off
}
digitalWrite(LEDa,0); //next ten lines keep two lights from being lit
digitalWrite(LEDb,0); //at the same time
digitalWrite(LEDc,0);
digitalWrite(LEDd,0);
digitalWrite(LEDe,0); // DISABLE FOR A BETTER EFFECT
digitalWrite(LEDf,0);
digitalWrite(LEDg,0);
digitalWrite(LEDh,0);
digitalWrite(LEDi,0);
digitalWrite(LEDj,0);
randnum = random(1,11); //change randnum
randelay = random(5,40); //change random delay number
count++;