This code will flash as many lights as you want in any order by only changing the numbers in the first two lines.
// Flashing lights demo by Grumpy Mike
#define inSequence 9
int timeDealy [] = { 400,200,100,800,200,1000,300,400,600 }; // time delay between change
byte pinToggle [] = { 9,5,8,10,9,5,8,10,9 }; // pin to change - matches up with above times
void setup() {
for(int i =0; i<inSequence; i++){
pinMode(pinToggle[i],OUTPUT); // set all the pins you will use to outputs
}
}
void loop() {
static int nextLight = 0;
byte temp = digitalRead(pinToggle[nextLight]);
if( temp ) {
digitalWrite(pinToggle[nextLight], LOW);
}
else {
digitalWrite(pinToggle[nextLight], HIGH);
}
delay(timeDealy[nextLight]);
nextLight++;
if(nextLight >= inSequence) nextLight = 0;
}
The line
#define inSequence 9
Defines the number of steps in the sequence, this number must match the number of elements in the next two lines.
int timeDealy [] = { 400,200,100,800,200,1000,300,400,600 }; // time delay between change
Each number is the delay before the next change.
byte pinToggle [] = { 9,5,8,10,9,5,8,10,9 }; // pin to change - matches up with above times
These are the pins to toggle ( change from on to off or off to on ) on each change.
Have fun playing about with this.
When you have it under your belt ask again about changing the flashing pattern.