#include <LiquidCrystal_I2C.h> // LCD I2C library
// Set LCD address, number of columns and rows
// If you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init(); // Initialize LCD (can also use lcd.init())
lcd.backlight(); // Turn on LCD backlight
pinMode(19, OUTPUT);
pinMode(18, INPUT);
}
void loop() {
int pushButton = digitalRead(18);
while (pushButton == pdTRUE){
lcd.clear(); // Clear the screen to avoid overlapping text
lcd.setCursor(0, 0); // Set cursor to first column, first row
lcd.print("Button is PUSH!"); // Print message on first row
lcd.setCursor(0, 1); // Set cursor to first column, second row
lcd.print("Time: ");
lcd.print(millis() / 1000); // Display seconds since start
lcd.print("s "); // Clear remaining characters
delay(1000); // Update every 1 second (reduced for better responsiveness)
digitalWrite(19, HIGH);
delay(300);
digitalWrite(19, LOW);
delay(300);
}
lcd.clear(); // Clear the screen to avoid overlapping text
lcd.setCursor(0, 0); // Set cursor to first column, first row
lcd.print("Button NOT PUSH!"); // Print message on first row
delay(1000);
}