int timer = 1000; //set the timer
int ledPin1 = 1;
int ledPin2 = 2;
int ledPin3 = 3;
const int buzzer = 4;
const int button1= 8;
const int button2= 9;
const int button3= 10;
void setup() {
// use a for loop to initialize each pin as an output:
for (int thisPin = 1; thisPin < 5; thisPin++) {
pinMode(thisPin, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
}
}
void loop() {
//Configure the red button sequence
int value1=digitalRead((button1));
if(value1==0){
for (int thisPin = 1; thisPin < 5; thisPin++) { // loop from the lowest pin to the highest:
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
if (thisPin == 4) {
tone(buzzer,1000);
delay(1000);
noTone(buzzer);
}
// turn the pin off:
digitalWrite(thisPin, LOW);
}
//loop pin from the highest straight
for (int thisPin = 4; thisPin = 1;) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
break; //break loop
}
}
//Configure the green button sequence
int value2=digitalRead((button2));
if(value2==0){
for (int thisPin =1; thisPin < 5; thisPin++) { // loop from the lowest pin to the highest
//turn the pin and buzzer on
digitalWrite(thisPin, HIGH);
delay(timer);
if (thisPin==4) {
tone(buzzer,1000);
delay(1000);
noTone(buzzer);
}
digitalWrite(thisPin, LOW);
}
for (int thisPin = 4; thisPin >=1; thisPin--){
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}
//configure the yellow button sequence
int value3=digitalRead((button3));
if(value3==0){ //if yellow button is pressed
//led light 1 & 2 on
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
delay(timer);
//led light 1 & 2 off
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
//led light 3 and buzzer on
digitalWrite(ledPin3, HIGH);
tone(buzzer,1000);
delay(1000);
//led light 3 and buzzer off
noTone(buzzer);
digitalWrite(ledPin3, LOW);
}
}