// Define the LED pins
const int redLed = 6; // Red LED pin
const int yellowLed = 4; // Yellow LED pin
const int greenLed = 2; // Green LED pin
// Define the timing for each light (in milliseconds)
const int redTime = 5000; // Red light duration (10 seconds)
const int yellowTime = 2000; // Yellow light duration (2 seconds)
const int greenTime = 4000; // Green light duration (8 seconds)
void setup() {
// Initialize the LED pins as outputs
pinMode(redLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}
void loop() {
// Red light on
digitalWrite(redLed, HIGH);
delay(redTime);
// Red light off, Yellow light on
digitalWrite(redLed, LOW);
digitalWrite(yellowLed, HIGH);
delay(yellowTime);
// Yellow light off, Green light on
digitalWrite(yellowLed, LOW);
digitalWrite(greenLed, HIGH);
delay(greenTime);
// Green light off, Yellow light on
digitalWrite(greenLed, LOW);
digitalWrite(yellowLed, HIGH);
delay(yellowTime);
// Yellow light off, loop will restart with red light
digitalWrite(yellowLed, LOW);
}