int switchState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
switchState = digitalRead(2);
if (switchState == LOW){
// if the the button is not pressed then do the following
digitalWrite(3, HIGH); //Red light ON
digitalWrite(4, LOW); //Yellow light OFF
digitalWrite(5, LOW); //green light OFF
}
else {
// if instead the button is pressed then do the following
digitalWrite(3, LOW); //Red light OFF
digitalWrite(4, LOW); //Yellow light OFF
digitalWrite(5, HIGH); //green light ON
delay(250); // WAIT FOR A QUARTER SECOND
// toggle the LEDs
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); // wait for a quarter second
}
} // GO BACK TO THE BEGINNING OF THE LOOP