/*
Wokwi | questions
I can not get get this code to work.
Crisshana - 11:22 AM November 27, 2025
https://wokwi.com/projects/448790840721583105?gh=1
*/
/*
Simple traffic light demo
*/
const unsigned long STATE_DELAYS[] = {
1000, 4000, 2000, 1000, 4000, 2000
};
const int LED_PINS[] = {13, 12, 14, 27, 26, 25};
const bool LED_STATES[][6] = {
{0, 0, 1, 0, 0, 1}, // all stop
{1, 0, 0, 0, 0, 1}, // NS go
{0, 1, 0, 0, 0, 1}, // NS caution
{0, 0, 1, 0, 0, 1}, // all stop
{0, 0, 1, 1, 0, 0}, // EW go
{0, 0, 1, 0, 1, 0}, // EW caution
};
unsigned long prevTime = 0;
int state = 0;
void setup() {
Serial.begin(115200);
for (int i = 0; i < 6; i++) {
pinMode(LED_PINS[i], OUTPUT);
}
Serial.println("\nTraffic Light Demo");
}
void loop() {
delay(10); // this speeds up the Wokwi simulation
// set all the LEDs
for (int led = 0; led < 6; led++) {
digitalWrite(LED_PINS[led], LED_STATES[state][led]);
}
// change the state after the correct delay
if (millis() - prevTime >= STATE_DELAYS[state]) {
prevTime = millis();
state++;
if (state == 6) state = 0;
}
}North/South
East/West