int lampuMerah[4] = {4, 13, 7, 8};
int lampuKuning[4] = {3, 6, 9, 12};
int lampuHijau[4] = {4, 7, 10, 13};
int delayMerah = 5000;
int delayKuning = 2000;
int delayHijau = 5000;
void setup() {
for (int i = 0; i < 4; i++) {
pinMode(lampuMerah[i], OUTPUT);
pinMode(lampuKuning[i], OUTPUT);
pinMode(lampuHijau[i], OUTPUT);
}
}
void nyalakanLampu(int simpang, int warnaHijau, int warnaKuning) {
for (int i = 0; i < 4; i++) {
digitalWrite(lampuHijau[i], LOW);
digitalWrite(lampuKuning[i], LOW);
digitalWrite(lampuMerah[i], HIGH);
}
digitalWrite(lampuMerah[simpang], LOW);
digitalWrite(lampuKuning[simpang], HIGH);
delay(warnaKuning);
digitalWrite(lampuKuning[simpang], LOW);
digitalWrite(lampuHijau[simpang], HIGH);
delay(warnaHijau);
digitalWrite(lampuHijau[simpang], LOW);
digitalWrite(lampuKuning[simpang], HIGH);
delay(warnaKuning);
digitalWrite(lampuKuning[simpang], LOW);
digitalWrite(lampuMerah[simpang], HIGH);
}
void loop() {
nyalakanLampu(0, delayHijau, delayKuning);
nyalakanLampu(1, delayHijau, delayKuning);
nyalakanLampu(2, delayHijau, delayKuning);
nyalakanLampu(3, delayHijau, delayKuning);
}