#include <Wire.h> // Include the Wire library for I2C communication
#include <LiquidCrystal_I2C.h>
// Define LCD properties
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the I2C address and LCD dimensions
int red = 7;
int yel = 6;
int gre = 5;
int button = 4;
int d = 2000;
void setup() {
// put your setup code here, to run once:
pinMode(button, INPUT_PULLUP);
pinMode(red, OUTPUT);
pinMode(yel, OUTPUT);
pinMode(gre, OUTPUT);
Serial.begin(9600);
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
lcd.print("Tahan tombol");
lcd.setCursor(0,1);
lcd.print("untuk menyebrang"); // Print initial text on the LCD
}
void loop() {
if (digitalRead(button) == LOW) {
Serial.println("Button pressed");
lcd.clear();
lcd.print("Waktu menyebrang");
lcd.setCursor(0,1);
lcd.print("3 detik, Hati2");
digitalWrite(red, HIGH);
digitalWrite(yel, LOW);
digitalWrite(gre, LOW);
delay(3000);
} else {
lcd.clear();
lcd.print("Tahan tombol");
lcd.setCursor(0,1);
lcd.print("untuk menyebrang"); // Print initial text on the LCD
digitalWrite(red, HIGH);
digitalWrite(yel, LOW);
digitalWrite(gre, LOW);
delay(d);
digitalWrite(yel, HIGH);
digitalWrite(red, LOW);
digitalWrite(gre, LOW);
delay(d);
digitalWrite(gre, HIGH);
digitalWrite(yel, LOW);
digitalWrite(red, LOW);
delay(d);
}
}