#include <LiquidCrystal_I2C.h> // LiquidCrystal I2C - Version: 1.1.1
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // LCD HEX address 0x27
#define Menu_inc 6
#define Menu_dec 7
#define Menu 8
int Menu_Up = 0;
int Menu_Dn = 0;
int Menu_Sel = 0;
unsigned long a = 0; //
unsigned long b = 3000; // time for long press on menu button
unsigned long Sec = 0;
unsigned long Mins = 0;
unsigned long Hours = 0;
int activetime = 0;
int starttime = 0;
int prevoustime = 0;
int c = 0;
int d = 0;
unsigned long startTime = 0;
unsigned long elapsedTime = 0;
boolean buttonState = LOW;
boolean lastButtonState = LOW;
void setup() {
Serial.begin(9600);
pinMode(Menu_inc, INPUT_PULLUP);
pinMode(Menu_dec, INPUT_PULLUP);
pinMode(Menu, INPUT_PULLUP);
a = millis();
lcd.init(); // initialize the lcd
lcd.backlight(); // turns on the backlight
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Anne and Johns"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to first row
lcd.print("Heating "); // print out to LCD
delay(3000);
lcd.clear();
}
void loop() {
Menu_Up = digitalRead(Menu_inc);
Menu_Dn = digitalRead(Menu_dec);
Menu_Sel = digitalRead(Menu);
buttonState = digitalRead(Menu);
// if (Menu_Up == LOW) lcd.init(), lcd.backlight(), lcd.setCursor(0, 2), lcd.print("Menu+ Pressed");
// if (Menu_Dn == LOW) lcd.init(), lcd.backlight(), lcd.setCursor(0, 2), lcd.print("Menu- Pressed");
//+++++++++++++++++++++Setting the timer for the menu++++++++++++++++++++++++++++++++++++++++++
if (buttonState != lastButtonState and d == 0) {if (buttonState == LOW) startTime = millis();}
if (buttonState == HIGH and d == 0) elapsedTime = 0;
if (buttonState == LOW and d == 0) elapsedTime = millis() - startTime;
lastButtonState = buttonState;
//==============================================================================================
if (elapsedTime > b and d == 0) d = 1, lcd.clear();
if (d == 0){
activetime = (millis() / 1000) - starttime;
if (prevoustime < activetime) Sec++, prevoustime = activetime;
if (Sec > 59) Mins++, Sec = 0;
if (Mins > 59) Hours++, Mins = 0;
if (Hours > 23) Hours = 0;
if (Menu_Up == LOW) Hours++, delay(250);
if (Hours < 10) lcd.setCursor(0,0), lcd.print("0"), lcd.setCursor(1, 0);
if (Hours >= 10) lcd.setCursor(0,0);
lcd.print(Hours);
lcd.setCursor(2,0);
lcd.print(":");
if (Mins < 10) lcd.setCursor(3,0), lcd.print("0"), lcd.setCursor(4,0), lcd.print(Mins);
if (Mins >= 10) lcd.setCursor(3,0), lcd.print(Mins);
lcd.setCursor(5,0);
// lcd.print(":");
// if (Sec < 10)lcd.setCursor(6,0), lcd.print("0"), lcd.setCursor(7,0), lcd.print(Sec);
// if (Sec >= 10) lcd.setCursor(6,0), lcd.print(Sec);
}
if (Menu_Dn == LOW and d == 1) d = 0, lcd.clear();
//set the clock so that the time shifts to most relavent number leading zero (01) (10)
//below 10
Serial.print(d);
Serial.print(" Elapsed Timer =");
Serial.println(elapsedTime);
if (d == 1){
lcd.setCursor(1,0), lcd.print("Set Time");
lcd.setCursor(1, 1), lcd.print("Set On/Off");
if (Menu_Sel == LOW and d == 1 and c == 0) lcd.setCursor (0, 0), lcd.print("#"), c == 1, delay(100);
if (Menu_Sel == LOW and d == 1 and c == 1) lcd.setCursor (0, 1), lcd.print("#"), c == 0, delay(100);
}
}