// declare constant const int switchPin = 8; // declare variables int switchState = 0; int prevSwitchState = 0; unsigned long previousTime = 0;// positive variable 32 bit, can count up to 4,294,967,295. will hold the time the LED was last changed int led =2 ;// will be used to count which LED is the next one to be turned on. start out with pin 2 long interval = 1000;// interval between each LED turning on //************************************************************************* void setup() { Serial.begin(9600);// open serial port, 9600 bits per second for (int x = 2; x < 8; x++) {// LEDs connected to digital 2 - 7 pinMode(x, OUTPUT);// declare LED pins as OUTPUT } pinMode(switchPin, INPUT);// declare Switch pin as an INPUT }//************************************************************************ void loop() { unsigned long currentTime = millis();// get the amount of time the Arduino has been running and store it in a local variable if (currentTime - previousTime > interval) { previousTime = currentTime; digitalWrite(led, HIGH); led++; if (led == 7) {// to check if the LED on pin 7 is turned on } } switchState = digitalRead(switchPin);// read the switch value into the switchState variable Serial.println(switchState);// print the switchState variable if (switchState != prevSwitchState) {// checks to see if switchState does not equal prevSwitchState for (int x = 2; x < 8; x++) { digitalWrite(x, LOW);// if they are different, turn the all LEDs off } led = 2;// return the led variable to the first pin previousTime = currentTime;// reset the timer for the LEDs by seting previousTime to currentTime } prevSwitchState = switchState;// save the switch state in prevSwitchState , so you can compare it to the value you get for switchState in the next loop() }