From d02ca2a130eec444a203dae0d056cf6a76fd0316 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 8 Jul 2020 23:38:59 +0300 Subject: Improved main controller input and clock implementations --- remihap/remihap.ino | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'remihap') diff --git a/remihap/remihap.ino b/remihap/remihap.ino index 034e692..48123fb 100644 --- a/remihap/remihap.ino +++ b/remihap/remihap.ino @@ -8,7 +8,7 @@ #define LCD_COLS 16 #define MSG_ERR_R1 " Error! " -#define ERROR_VISIBILITY_TIMEOUT 2000 +#define ERROR_VISIBILITY_TIMEOUT 500 #define MSG_ERR_DAY " Invalid day " #define MSG_ERR_HOUR " Invalid hour " @@ -453,6 +453,8 @@ void setup() char key; +unsigned long lastTime; + void loop() { if (menu == mainMenu) { @@ -469,28 +471,31 @@ void loop() dispensePill(3); // dispense correct pill alarm(millis()); } - delay(990); + delay(10); - seconds++; + if (millis() - lastTime >= 1000) { + lastTime = millis(); + seconds++; - if(seconds > 59) { - seconds = 0; - minutes++; - } - if (minutes > 59) { - minutes = 0; - hours++; - } - if (hours > 23) { - hours = 0; - day++; - } - if (day > maxDays[month]) { - day = 1; - month++; - } - if (month > 12) { - month = 1; - year++; + if(seconds > 59) { + seconds = 0; + minutes++; + } + if (minutes > 59) { + minutes = 0; + hours++; + } + if (hours > 23) { + hours = 0; + day++; + } + if (day > maxDays[month]) { + day = 1; + month++; + } + if (month > 12) { + month = 1; + year++; + } } } -- cgit v1.2.3