// Define pin numbers for the LEDs
const int greenLED = 16; // Adjust this pin according to your setup
const int yellowLED = 17; // Adjust this pin according to your setup
const int redLED = 18; // Adjust this pin according to your setup
void setup() {
// Initialize the serial monitor
Serial.begin(115200);
// Set the LED pins as OUTPUT
pinMode(greenLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(redLED, OUTPUT);
// Start with all LEDs off
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, LOW);
}
void loop() {
// Continuous sequence
Serial.println("Go for Green");
blinkLED(greenLED, 20); // Green LED for 20 seconds
Serial.println("Wait for Yellow");
blinkLED(yellowLED, 3); // Yellow LED for 3 seconds
Serial.println("Stop for Red");
blinkLED(redLED, 2); // Red LED for 2 seconds
}
void blinkLED(int pin, int duration) {
unsigned long endTime = millis() + (duration * 1000); // Calculate the end time based on duration
while (millis() < endTime) {
digitalWrite(pin, HIGH); // Turn LED on
delay(1000); // Wait for 1 second
}
digitalWrite(pin, LOW); // Turn LED off after duration
}