unsigned long previousTime=0;
int switchState=0;
int prevswitchState=0;
int led=2; //led lights start from 2 and move up to 7
long interval=1000; //1 second
void setup() {
for(int x=2;x<8;x++){ //for every number from 2 to 7, make an OUTPUT
pinMode(x,OUTPUT);
}
pinMode(8,INPUT);
}
void loop() {
unsigned long currentTime=millis(); //the Arduino keeps track of the current time
if(currentTime - previousTime > interval) { //checks to see if enough time has passed
previousTime=currentTime;
digitalWrite(led, HIGH);
led++; //every time an interval passes, the next light turns on
}
if (led>7) //if all the lights are on, flash.
{
delay(interval);
led=2;
for(int x=0; x<5; x++) {
for(int x=2;x<8;x++){digitalWrite(x,LOW);}
delay(100);
for(int x=2;x<8;x++){digitalWrite(x,HIGH);}
delay(100);
for(int x=2;x<8;x++){digitalWrite(x,LOW);}
}
}
switchState=digitalRead(8); //if the switched is pressed, restart
if(switchState !=prevswitchState){
for(int x=2;x<8;x++){
digitalWrite(x,LOW);
}
led=2;
previousTime=currentTime;
}
prevswitchState=switchState;
}