#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int SecondPin = 34;
const int MinutePin = 35;
const int HourPin = 32;
struct Button {
const uint8_t PIN;
uint32_t numberKeyPresses;
bool pressed;
};
Button Start {23,0,false};
Button Reset = {18, 0, false};
unsigned long button_time = 0;
unsigned long last_button_time = 0;
volatile int total =0;
void IRAM_ATTR isr() {
button_time = millis();
if (button_time - last_button_time > 250)
{
Reset.numberKeyPresses++;
Reset.pressed = true;
last_button_time = button_time;
total =0;
}
}
void IRAM_ATTR start() {
button_time = millis();
if (button_time - last_button_time > 250)
{
Start.numberKeyPresses++;
Start.pressed = true;
last_button_time = button_time;
}
}
int Second = 0;
int second=0;
int Minute =0;
int minute =0;
int Hour =0;
int hour =0;
void setup() {
Serial.begin(115200);
pinMode (4,OUTPUT);
pinMode(Start.PIN, INPUT_PULLUP);
attachInterrupt(Start.PIN,start,FALLING);
attachInterrupt(Reset.PIN, isr, FALLING);
lcd.init();
lcd.clear();
lcd.backlight();
lcd.setCursor(2,0);
lcd.print("Time Remaining");
lcd.setCursor(2,1);
delay(1000);
}
void loop() {
// Reading potentiometer value
Second = analogRead(SecondPin);
second = map(Second, 0, 4095, 0, 60);
Serial.printf("The second value is %d \n",second );
delay(500);
Minute = analogRead(MinutePin);
minute = map(Minute, 0, 4095, 0, 60);
Serial.printf("The minute value is %d \n",minute );
delay(500);
Hour = analogRead(HourPin);
hour = map(Hour, 0, 4095, 0, 60);
Serial.printf("The Hour value is %d \n",hour );
delay(500);
if(Start.pressed){
total = 1000*second+60*1000*minute+60*60*1000*hour;
if(total >= 0){
digitalWrite(4, HIGH);
while(total >= 100){
delay(100);
total -=100;
Serial.printf("Total delay remaining %d \n" ,total);\
lcd.setCursor(2,1);
lcd.print(total);
}
}
digitalWrite(4,LOW);
Start.pressed = false;
}
delay(500);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Time Remaining");
lcd.setCursor(2,1);
lcd.print("0");
}