int BUTTON = 13;
int RED1 = 1;
int YELLOW1 = 2;
int GREEN1 = 3;
int RED2 = 4;
int YELLOW2 = 5;
int GREEN2 = 6;
int RED3 = 7;
int YELLOW3 = 8;
int GREEN3 = 9;
int RED4 = 10;
int YELLOW4 = 11;
int GREEN4 = 12;
int GREEN_TIME = 2000;
int YELLOW_TIME = 1000;
int i;
void setup() {
pinMode(BUTTON, INPUT_PULLUP);
pinMode(RED1, OUTPUT);
pinMode(YELLOW1, OUTPUT);
pinMode(GREEN1, OUTPUT);
pinMode(RED2, OUTPUT);
pinMode(YELLOW2, OUTPUT);
pinMode(GREEN2, OUTPUT);
pinMode(RED3, OUTPUT);
pinMode(YELLOW3, OUTPUT);
pinMode(GREEN3, OUTPUT);
pinMode(RED4, OUTPUT);
pinMode(YELLOW4, OUTPUT);
pinMode(GREEN4, OUTPUT);
}
void loop() {
if(digitalRead(BUTTON) == LOW){
for(i = 1; i <= 2 ; i++){
digitalWrite(GREEN1, HIGH);
digitalWrite(GREEN3, HIGH);
digitalWrite(RED2, HIGH);
digitalWrite(RED4, HIGH);
delay(GREEN_TIME);
digitalWrite(GREEN1, LOW);
digitalWrite(YELLOW1, HIGH);
digitalWrite(GREEN3, LOW);
digitalWrite(YELLOW3, HIGH);
delay(YELLOW_TIME);
digitalWrite(YELLOW1, LOW);
digitalWrite(RED1, HIGH);
digitalWrite(YELLOW3, LOW);
digitalWrite(RED3, HIGH);
digitalWrite(YELLOW2, LOW);
digitalWrite(RED2, LOW);
digitalWrite(GREEN2, HIGH);
digitalWrite(YELLOW4, LOW);
digitalWrite(RED4, LOW);
digitalWrite(GREEN4, HIGH);
delay(GREEN_TIME);
digitalWrite(GREEN2, LOW);
digitalWrite(YELLOW2, HIGH);
digitalWrite(GREEN4, LOW);
digitalWrite(YELLOW4, HIGH);
delay(YELLOW_TIME);
digitalWrite(YELLOW2, LOW);
digitalWrite(RED2, HIGH);
digitalWrite(YELLOW4, LOW);
digitalWrite(RED4, HIGH);
digitalWrite(RED1, LOW);
digitalWrite(GREEN1, HIGH);
digitalWrite(RED3, LOW);
digitalWrite(GREEN3, HIGH);
delay(GREEN_TIME);
}
}
else {
digitalWrite(YELLOW2, LOW);
digitalWrite(RED2, LOW);
digitalWrite(YELLOW4, LOW);
digitalWrite(RED4, LOW);
digitalWrite(RED1, LOW);
digitalWrite(GREEN1, LOW);
digitalWrite(RED3, LOW);
digitalWrite(GREEN3, LOW);
}
}