#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
int startButton = 2; // assign the start button to pin 2
int resetButton = 3; // assign the reset button to pin 3
int upButton = 4; // assign the up button to pin 4
int downButton = 5; // assign the down button to pin 5
int relayPin = 6; // assign the relay output to pin 6
int countDownTime = 600; // set the countdown time to 10 minutes (in seconds)
int countDownState = 0; // keep track of the current state of the countdown timer
int countDownStart = 0; // keep track of when the countdown timer was started
int countDownCurrent = 0;// keep track of the current time on the countdown timer
void setup() {
lcd.init(); // initialize the LCD
lcd.backlight(); // turn on the backlight
pinMode(startButton, INPUT); // set the start button as an input
pinMode(resetButton, INPUT); // set the reset button as an input
pinMode(upButton, INPUT); // set the up button as an input
pinMode(downButton, INPUT); // set the down button as an input
pinMode(relayPin, OUTPUT); // set the relay pin as an output
lcd.setCursor(0,0); // set the LCD cursor to the first column of the first row
lcd.print("Countdown Timer"); // print the title
lcd.setCursor(0,1); // set the LCD cursor to the first column of the second row
lcd.print("Set Time: 10:00"); // print the initial countdown time
}
void loop() {
int startButtonState = digitalRead(startButton);
int resetButtonState = digitalRead(resetButton);
int upButtonState = digitalRead(upButton);
int downButtonState = digitalRead(downButton);
if (resetButtonState == HIGH) { // if the reset button is pressed
countDownState = 0; // reset the countdown timer state
countDownCurrent = 0; // reset the current time on the countdown timer
digitalWrite(relayPin, LOW); // turn off the relay output
lcd.clear(); // clear the LCD screen
lcd.setCursor(0,0); // set the LCD cursor to the first column of the first row
lcd.print("Countdown Timer"); // reprint the title
lcd.setCursor(0,1); // set the LCD cursor to the first column of the second row
lcd.print("Set Time: 10:00"); // reset the countdown time
}
if (startButtonState == HIGH && countDownState == 0) { // if the start button is pressed and the timer is not running
countDownStart = millis(); // start the countdown timer
countDownState = millis ;
}
}