// Define the pins for each LED
const int redPin = 2;
const int yellowPin = 3;
const int greenPin = 4;
// Define timing for each state (in milliseconds)
const int greenDuration = 5000; // 5 seconds for green light
const int yellowDuration = 2000; // 2 seconds for yellow light
const int redDuration = 5000; // 5 seconds for red light
void setup() {
// Initialize the pins as outputs
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
// Green light
digitalWrite(greenPin, HIGH);
delay(greenDuration);
// Yellow light
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, HIGH);
delay(yellowDuration);
// Red light
digitalWrite(yellowPin, LOW);
digitalWrite(redPin, HIGH);
delay(redDuration);
// Red & Yellow light (Transition)
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, HIGH);
delay(yellowDuration / 2); // Half the duration of yellow light
// Turn off all lights (Transition)
digitalWrite(yellowPin, LOW);
delay(yellowDuration / 2); // Half the duration of yellow light
}