const int buttonPin = 2; // setting up the variable for the button pin int buttonState = 0; // start the button state as 0 (off) int loopStop = 0; // variable to stop the loop if button press interupts void setup() { pinMode(8, OUTPUT); // pins to LED pinMode(9, OUTPUT); // pins to LED pinMode(10, OUTPUT); // pins to LED pinMode(11, OUTPUT); // pins to LED pinMode(12, OUTPUT); // pins to LED pinMode(buttonPin, INPUT); // setting up button in as input } void loop() { if (loopStop == 1){ // if there was in interupt buttonState = HIGH; // the button was hit } else{ buttonState = digitalRead(buttonPin); // read the state of the button } if (buttonState == HIGH){ // if the button is pressed digitalWrite(8, HIGH); // all lights on digitalWrite(9, HIGH); // all lights on digitalWrite(10, HIGH); // all lights on digitalWrite(11, HIGH); // all lights on digitalWrite(12, HIGH); // all lights on loopStop = myDelay(4000); // personal timer function, wait 4 seconds if (loopStop == 1){ // if loop was interupted, start over return 0; } digitalWrite(8, LOW); // turn off top light loopStop = myDelay(4000); // personal timer function, wait 4 seconds if (loopStop == 1){ // if loop was interupted, start over return 0; } digitalWrite(9, LOW); // turn off second to top light loopStop = myDelay(4000); // personal timer function, wait 4 seconds if (loopStop == 1){ // if loop was interupted, start over return 0; } digitalWrite(10, LOW); // turn off middle light loopStop = myDelay(4000); // personal timer function, wait 4 seconds if (loopStop == 1){ // if loop was interupted, start over return 0; } digitalWrite(11, LOW); // turn off second to bottom light loopStop = myDelay(4000); // personal timer function, wait 4 seconds if (loopStop == 1){ // if loop was interupted, start over return 0; } digitalWrite(12, LOW); // turn off bottom light } else { // if the button was not pressed digitalWrite(8, LOW); // keep all lights off digitalWrite(9, LOW); // keep all lights off digitalWrite(10, LOW); // keep all lights off digitalWrite(11, LOW); // keep all lights off digitalWrite(12, LOW); // keep all lights off } } /* Normal delay() function does not allow button interupts to have an affect. * This is my own function that will wait for user specified milliseconds while also checking if the button gets pressed. * Input: Number of milliseconds to wait * Output: Returns 1 if the button was pressed */ int myDelay(unsigned long duration){ unsigned long start = millis(); // start the timer while (millis() - start <= duration){ // while the timer is still going int buttonState = digitalRead(buttonPin); // read the button state each millisecond if (buttonState == HIGH){ // if the button was pressed return 1; // return 1 and exit function } } }