#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int redled = 23;
int startButton = 15;
int buttoncount;
bool normal = false;
int timer = 5;
void setup() {
pinMode(redled, OUTPUT);
digitalWrite(redled, HIGH);
pinMode(startButton, INPUT_PULLUP);
}
void loop() {
if (digitalRead(startButton) == LOW) {
delay(200);
normal = true;
Wire.begin();
lcd.begin(16, 2);
lcd.setBacklight(HIGH);
lcd.print("Hello, I2C LCD!");
}
if (normal) {
digitalWrite(redled, LOW);
delay(500);
digitalWrite(redled, HIGH);
delay(500);
timer--;
// Convert timer from seconds to minutes:seconds
int minutes = timer / 60;
int seconds = timer % 60;
// Print the timer value on the LCD in MM:SS format
lcd.setCursor(0, 1);
if (minutes < 10) {
lcd.print("0"); // Add leading zero for minutes < 10
}
lcd.print(minutes);
lcd.print(":");
if (seconds < 10) {
lcd.print("0"); // Add leading zero for seconds < 10
}
lcd.print(seconds);
// If the timer reaches 0, stop the normal operation
if (timer == 0) {
normal = false;
lcd.clear();
lcd.print("Time's up!");
normal = false;
lcd.clear();
}
}
}