#include <LiquidCrystal.h>
// Initialize the LCD with I2C address 0x27 (check your specific LCD module)
LiquidCrystal lcd(12,11,5,4,3,2);
// Define pin numbers for LEDs
const int redPin = 9;
const int yellowPin = 10;
const int greenPin = 11;
void setup() {
// Initialize the LCD
lcd.begin( 16,2);
// Set LED pins as outputs
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
// No additional code required in loop for this simulation
}
void trafficLightCycle() {
while (true) {
// Red light
digitalWrite(redPin, HIGH);
lcd.clear();
lcd.print("Red Light");
delay(5000);
digitalWrite(redPin, LOW);
// Green light
digitalWrite(greenPin, HIGH);
lcd.clear();
lcd.print("Green Light");
delay(5000);
digitalWrite(greenPin, LOW);
// Yellow light
digitalWrite(yellowPin, HIGH);
lcd.clear();
lcd.print("Yellow Light");
delay(2000);
digitalWrite(yellowPin, LOW);
}
}