#include <LiquidCrystal_I2C.h>
// Define pins for the LEDs
const int redLedPin = 10;
const int greenLedPin = 11;
const int yellowLedPin = 12;
// Time intervals (in milliseconds)
const int redDuration = 5000; // 5 seconds for red light
const int greenDuration = 5000; // 5 seconds for green light
const int yellowDuration = 2000; // 2 seconds for yellow light
// Create an instance of the LiquidCrystal_I2C class
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD address 0x27, 16 columns, 2 rows
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight();
// Display initial information on the LCD
lcd.setCursor(0, 0);
lcd.print("Traffic Light");
lcd.setCursor(0, 1);
lcd.print("Name: YourName");
// Initialize the LED pins as outputs
pinMode(redLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
}
void loop() {
// Turn on the Green LED and update LCD
digitalWrite(greenLedPin, LOW);
digitalWrite(redLedPin, HIGH);
digitalWrite(yellowLedPin, LOW);
lcd.setCursor(0, 1);
lcd.print("Status: STOP ");
delay(greenDuration); // Wait for the green light duration
// Turn on the Yellow LED and update LCD
digitalWrite(greenLedPin, LOW);
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, HIGH);
lcd.setCursor(0, 1);
lcd.print("Status: GET READY ");
delay(yellowDuration); // Wait for the yellow light duration
// Turn on the Red LED and update LCD
digitalWrite(greenLedPin, HIGH);
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, LOW);
lcd.setCursor(0, 1);
lcd.print("Status: GO ");
delay(redDuration); // Wait for the red light duration
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL
led1:A
led1:C
led2:A
led2:C
led3:A
led3:C