/////// Three door with UV, Timer, Door Lock, CFL, Blower and sensors for UV //////
// includes
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#include <RTClib.h>
#include "Countimer.h"
// Declaration of LCDS & RTC
LiquidCrystal_I2C lcd1(0x27, 16, 2); // display 1
LiquidCrystal_I2C lcd2(0x26, 16, 2); // display 2
LiquidCrystal_I2C lcd3(0x25, 16, 2); // display 3
RTC_DS1307 rtc;
// Forward declarations for settings pages
void drawLockTimePage();
void drawBlowerTimePage();
void drawUvTimePage();
void drawUvModePage();
void drawDlModePage();
void drawBlowerModePage();
void drawTypePage();
void handleGenericTimePage(int &targetVal, int eepromAddr, int nextMenu, void (*drawFunc)(), int prevMenu, int prevStepNoo, bool emgPressed);
void handleGenericModePage(bool &modeVal, int eepromAddr, int nextMenuManual, int nextMenuAuto, void (*drawFunc)(), int prevMenu, int prevStepNoo, bool emgPressed, bool activeLowVal);
Countimer hourmeter;
Countimer uvtDown;
byte downArrow[8] = {
0b00100, // *
0b00100, // *
0b00100, // *
0b00100, // *
0b10101, // * * *
0b01110, // ***
0b00100, // *
0b00000 //
};
// int PD_PIN = 2; // for saving TUV
unsigned char Dooor1, Dooor2, Dooor3, Count;
char formatted_hrtime[4];
char formatted_mintime[2];
//const unsigned long eventInterval = 60000; //min
const unsigned long eventIntervalaa = 60000; //min
//const unsigned long saveInterval = 900000; //15mins
unsigned long previousTimeaa = 0;
unsigned long Countsec = 0;
unsigned long Countmin = 0;
unsigned long Counthour = 0;
uint32_t lastRtcSec = 0;
unsigned long previousTimett = 0;
unsigned long timermin = 0;
unsigned long timerhour = 0;
bool timeraa = 0;
bool uvpause = 0;
int setmin = 5;
int sethour = 10;
//// too use millis ////
const unsigned long eventInterval = 1000;
const unsigned long saveInterval = 900000; //15mins
unsigned long previousTime = 0;
unsigned long lastMenuActivity = 0;
unsigned long lastMenuTransitionTime = 0;
int stepNo = 0; // for Menu
int stepNoo = 0;
int passNo = 0;
byte nextButtonState = LOW;
const int door1sen = A0;
const int door2sen = A1;
const int door3sen = A6;
const int Emergence = 0;
bool door1val = 0;
bool door2val = 0;
bool door3val = 0;
bool timer = false;
bool rst = false;
bool buzzerr = true;
bool Blowerauto = false;
bool doorlock = false;
bool doorlookbool = false;
bool postCloseLockActive = false;
unsigned long postCloseLockStart = 0;
// Buzzer control variables
unsigned long doorOpenTime = 0;
bool doorWasOpen = false;
unsigned long uvCompletedTime = 0;
bool uvCompletionAlarmActive = false;
// Configurable Timers and Modes
bool CLFauto = true;
int dlockTsec = 5; // default door lock open time: 5s
int clfTsec = 10; // default CFL stay ON time: 10s
int blowTsec = 10; // default blower ON time: 10s
int uvtTmin = 1; // default UV ON time: 1m
bool uvManualMode = true; // default UV mode: Manual
bool isStatic = false; // default Type: Dynamic
// Non-blocking timer variables for CLF and Blower auto-operation
bool clfTimerActive = false;
unsigned long clfTimerStart = 0;
bool blowerTimerActive = false;
unsigned long blowerTimerStart = 0;
// menu configuration helpers
bool menuclfpusheddcl = 0;
// EEPROM Address Constants for settings
const int EE_ADDR_UV_AUTO = 20;
const int EE_ADDR_UV_HOUR = 21;
const int EE_ADDR_UV_MIN = 23;
const int EE_ADDR_BUZZER = 24;
const int EE_ADDR_DOORLOCK = 25;
const int EE_ADDR_CLF_AUTO = 26;
const int EE_ADDR_BLOWER_AUTO = 27;
const int EE_ADDR_DLOCK_TIME = 28;
const int EE_ADDR_CLF_TIME = 30;
const int EE_ADDR_BLOWER_SEC = 32;
const int EE_ADDR_UV_TIME = 34;
const int EE_ADDR_UV_MANUAL = 36;
const int EE_ADDR_IS_STATIC = 38;
// bool dpsensor = false;
// save interval
int PD_PIN = 2;
unsigned long Count2 = 0;
int EE_ADDR = 1;
unsigned long value;
const unsigned long saveInterval2 = 1000;
unsigned long previousTime2 = 0;
// save interval
const int door1 = 3;
const int door2 = 4;
const int door3 = A2;
const int uv = 5;
const int clf = 6;
const int blow = 7;
const int buzzer = 2;
const int door1but = 8;
const int door2but = 9;
const int door3but = A3;
const int uvbut = 10;
const int clfbut = 11;
const int blowbut = 12;
const int menubut = 13;
int currentMenu = 0;
bool menuCursorOnRight = false;
bool door1butval = 0;
int door1lightON = 0;
int door1pushed = 0;
bool door2butval = 0;
int door2lightON = 0;
int door2pushed = 0;
bool door3butval = 0;
int door3lightON = 0;
int door3pushed = 0;
bool uvbutval = 0;
int uvlightON = 0;
int uvpushed = 0;
bool clfbutval = 0;
int clflightON = 0;
int clfpushed = 0;
bool menuclflightON = 0;
bool menuclflightONN = 0;
bool menuclfpushed = 0;
bool menuclfpushedd = 0;
bool menuclfpusheddtr = 0;
bool menuclfpushedddl = 0;
bool menuclfpusheddba = 0;
bool menuclfpusheddbr = 0;
bool blowbutval = 0;
int blowlightON = 0;
int blowpushed = 0;
bool Emergencebutval = 0;
int EmergencelightON = 0;
int Emergencepushed = 0;
bool HHH = 0;
bool HLL = 0;
bool LHL = 0;
bool LLH = 0;
bool LHH = 0;
bool HHL = 0;
bool HLH = 0;
bool LLL = 0;
bool didMyOneTimeAction5 = false;
int stepNo3 = 0;
bool menuBlinkOn = true;
// New menu state variables for separate settings pages (DL, CFL, Blower)
bool inEditMode = false;
bool popupSetTimeSelected = true;
int digitIndex = 0;
int tempDigits[4] = {0, 0, 0, 0};
bool door1first = 0;
bool door2first = 0;
bool door3first = 0;
bool senoropendoor1 = 0;
bool senoropendoor2 = 0;
bool senoropendoor3 = 0;
bool uvtimerbool = 0;
bool menubuttonState = 0;
int menulightON = 0;
int menupushed = 0;
boolean didMyOneTimeAction = false;
boolean didMyOneTimeAction2 = false;
boolean didMyOneTimeAction3 = false;
boolean didMyOneTimeAction4 = false;
bool oneTimeAfterDoorClose2 = 0;
bool oneTimeAfterDoorClose1 = 0;
bool oneTimeAfterDoorClose3 = 0;
int UVTsec = 0;
int UVTmint = 1;
int UVThour = 0;
int hourTsec = 00;
int hourTmint = 00;
int hourThour = 9999;
int EE_ADDR_hr = 10;
int EE_ADDR_min = 14;
int EE_ADDR_sec = 18;
unsigned long store_hr = 0;
unsigned long store_min = 0;
//Name setting initialisation
int cursorpt = 0;
char alphabet[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ',', '*', '-', '_', '@', '#', '.', ' '};
// initialize the alphabet index
int alphabetIndex = 0;
char stringArray[18];
int stringIndex = 0;
int sensorValue = 0;
void printLcd(LiquidCrystal_I2C &lcd, int col, int row, const __FlashStringHelper* msg) {
lcd.setCursor(col, row);
lcd.print(msg);
}
void printAllLcds(int col, int row, const __FlashStringHelper* msg) {
printLcd(lcd1, col, row, msg);
printLcd(lcd2, col, row, msg);
printLcd(lcd3, col, row, msg);
}
void clearAllLcds() {
lcd1.clear();
lcd2.clear();
lcd3.clear();
}
void printAllLcdsStr(int col, int row, const char* msg) {
lcd1.setCursor(col, row); lcd1.print(msg);
lcd2.setCursor(col, row); lcd2.print(msg);
lcd3.setCursor(col, row); lcd3.print(msg);
}
bool checkAnyDoorButtonPressed() {
static bool prevDoor1 = LOW;
static bool prevDoor2 = LOW;
static bool prevDoor3 = LOW;
bool pressed = ((door1butval == HIGH && prevDoor1 == LOW) ||
(door2butval == HIGH && prevDoor2 == LOW) ||
(door3butval == HIGH && prevDoor3 == LOW));
prevDoor1 = door1butval;
prevDoor2 = door2butval;
prevDoor3 = door3butval;
return pressed;
}
void printCancelOkRow() {
if (!menuCursorOnRight) {
printAllLcds(0, 1, F("\x01 Cancel "));
} else {
printAllLcds(0, 1, F("\x01 OK "));
}
}
void printManualAutoRow() {
if (!menuCursorOnRight) {
printAllLcds(0, 1, F("\x01 Manual "));
} else {
printAllLcds(0, 1, F("\x01 Auto "));
}
}
void checkEmergencyButton() {
Emergencebutval = 1 - digitalRead(Emergence);
if (Emergencebutval == HIGH && EmergencelightON == LOW) {
Emergencepushed = 1 - Emergencepushed;
delay(100);
}
EmergencelightON = Emergencebutval;
}
void updateDoorStates() {
door1val = digitalRead(door1sen) && (digitalRead(door1) == LOW);
door2val = digitalRead(door2sen) && (digitalRead(door2) == LOW);
if ((analogRead(door3sen) > 0) && (digitalRead(door3) == LOW)) {
door3val = 1;
} else {
door3val = 0;
}
}
void saveSettingsToEEPROM() {
EEPROM.update(EE_ADDR_UV_AUTO, timer ? 1 : 0);
EEPROM.update(EE_ADDR_UV_HOUR, UVThour);
EEPROM.update(EE_ADDR_UV_MIN, UVTmint);
EEPROM.update(EE_ADDR_BUZZER, buzzerr ? 1 : 0);
EEPROM.update(EE_ADDR_DOORLOCK, doorlock ? 1 : 0);
EEPROM.update(EE_ADDR_CLF_AUTO, CLFauto ? 1 : 0);
EEPROM.update(EE_ADDR_BLOWER_AUTO, Blowerauto ? 1 : 0);
EEPROM.put(EE_ADDR_DLOCK_TIME, dlockTsec);
EEPROM.put(EE_ADDR_CLF_TIME, clfTsec);
EEPROM.put(EE_ADDR_BLOWER_SEC, blowTsec);
EEPROM.put(EE_ADDR_UV_TIME, uvtTmin);
EEPROM.update(EE_ADDR_UV_MANUAL, uvManualMode ? 1 : 0);
EEPROM.update(EE_ADDR_IS_STATIC, isStatic ? 1 : 0);
}
void loadSettingsFromEEPROM() {
if (EEPROM.read(19) != 0x42) {
// Initialize EEPROM with default values
EEPROM.update(19, 0x42);
dlockTsec = 5;
clfTsec = 10;
blowTsec = 10;
uvtTmin = 1;
UVThour = 0;
UVTmint = 1;
timer = false;
buzzerr = true;
doorlock = false; // Default DL mode: Manual (doorlock = false)
CLFauto = false; // Default CFL mode: Manual
Blowerauto = false;// Default Blower mode: Manual
uvManualMode = true;// Default UV mode: Manual
timer = !uvManualMode;
isStatic = false; // Default Type: Dynamic
saveSettingsToEEPROM(); // saves defaults
} else {
buzzerr = EEPROM.read(EE_ADDR_BUZZER) == 1;
doorlock = EEPROM.read(EE_ADDR_DOORLOCK) == 1;
CLFauto = false; // Always manual (turns ON on door open, OFF on door close)
Blowerauto = EEPROM.read(EE_ADDR_BLOWER_AUTO) == 1;
isStatic = EEPROM.read(EE_ADDR_IS_STATIC) == 1;
if (EEPROM.read(EE_ADDR_UV_MANUAL) == 255) {
uvManualMode = true;
} else {
uvManualMode = EEPROM.read(EE_ADDR_UV_MANUAL) == 1;
}
timer = !uvManualMode;
EEPROM.get(EE_ADDR_DLOCK_TIME, dlockTsec);
EEPROM.get(EE_ADDR_BLOWER_SEC, blowTsec);
EEPROM.get(EE_ADDR_UV_TIME, uvtTmin);
// Sanity checks
if (dlockTsec < 1 || dlockTsec > 9999) dlockTsec = 5;
if (clfTsec < 0 || clfTsec > 9999) clfTsec = 10;
if (blowTsec < 0 || blowTsec > 9999) blowTsec = 10;
if (uvtTmin < 0 || uvtTmin > 9999) {
// Fallback/migration from old UV hour and min setting
int oldHour = EEPROM.read(EE_ADDR_UV_HOUR);
int oldMin = EEPROM.read(EE_ADDR_UV_MIN);
if (oldHour >= 0 && oldHour <= 999 && oldMin >= 0 && oldMin < 60) {
uvtTmin = oldHour * 60 + oldMin;
} else {
uvtTmin = 1;
}
}
UVThour = uvtTmin / 60;
UVTmint = uvtTmin % 60;
}
// Synchronize menu helper variables
menuclfpusheddtr = timer ? HIGH : LOW;
menuclfpusheddbr = buzzerr ? HIGH : LOW;
menuclfpushedddl = doorlock ? HIGH : LOW;
menuclfpusheddba = Blowerauto ? HIGH : LOW;
menuclfpusheddcl = CLFauto ? HIGH : LOW;
}
//////////////////////////////// setup //////////////////////////////////////////////
void setup() {
Serial.begin(9600);
loadSettingsFromEEPROM();
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
} else {
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running, setting time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
// Disable internal pull-ups on SDA and SCL to use external pull-ups only
#if defined(__AVR__)
digitalWrite(SDA, LOW);
digitalWrite(SCL, LOW);
#endif
pinMode(PD_PIN, INPUT);
EEPROM.get(EE_ADDR, Count);
attachInterrupt(digitalPinToInterrupt(PD_PIN), PD_ISR, FALLING );
if (Counthour > 9999) {
Counthour = 0;
}
if (Countmin > 59) {
Countmin = 0;
}
if (Countsec > 59) {
Countsec = 0;
}
//attachInterrupt(digitalPinToInterrupt(PD_PIN), PD_ISR,FALLING);
// hourmeter.setCounter(hourThour, hourTmint, hourTsec, hourmeter.COUNT_UP, hourmeterComplete, 0);
// hourmeter.setInterval(print_time2, 5000);
uvtDown.setCounter(UVThour, UVTmint, UVTsec, uvtDown.COUNT_DOWN, uvtDownComplete, 0);
// Call print_time2() method every 1s.
uvtDown.setInterval(uvtprint_time2, 1000);
lcd1.init();
lcd2.init();
lcd3.init();
lcd1.createChar(1, downArrow);
lcd2.createChar(1, downArrow);
lcd3.createChar(1, downArrow);
lcd1.backlight();
lcd2.backlight();
lcd3.backlight();
pinMode(door1sen, INPUT);
pinMode(door2sen, INPUT);
pinMode(door3sen, INPUT);
pinMode(door1but, INPUT);
pinMode(door2but, INPUT);
pinMode(door3but, INPUT);
pinMode(uvbut, INPUT);
pinMode(clfbut, INPUT);
pinMode(blowbut, INPUT);
pinMode(menubut, INPUT);
pinMode(Emergence, INPUT);
pinMode(door1, OUTPUT);
pinMode(door2, OUTPUT);
pinMode(door3, OUTPUT);
pinMode(uv, OUTPUT);
pinMode(clf, OUTPUT);
pinMode(blow, OUTPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(door1, HIGH);
digitalWrite(door2, HIGH);
digitalWrite(door3, HIGH);
digitalWrite(uv, LOW);
digitalWrite(clf, LOW);
digitalWrite(blow, LOW);
digitalWrite(buzzer, LOW);
lcd1.setCursor(4, 0);
lcd1.print("RJIS-DP2");
lcd1.setCursor(5, 1);
lcd1.print("Door 1");
lcd2.setCursor(4, 0);
lcd2.print("RJIS-DP2");
lcd2.setCursor(5, 1);
lcd2.print("Door 2");
lcd3.setCursor(4, 0);
lcd3.print("RJIS-DP2");
lcd3.setCursor(5, 1);
lcd3.print("Door 3");
//hourmeter.start();
uvpushed = 1;
delay(3000); // change this line if you want not to wait
lcd1.clear(); // clearn screen 1
lcd2.clear(); // clearn screen 2
lcd3.clear();
// lcd1.setCursor(6, 0);
// lcd1.print("0000:00");
// lcd2.setCursor(6, 0);
// lcd2.print("0000:00");
}
//////////////////////////////// Loop ///////////////////////////////////
void loop() { //loop
// Menu blink timer (toggles every 250ms)
static unsigned long lastMenuBlinkMillis = 0;
if (millis() - lastMenuBlinkMillis >= 250) {
lastMenuBlinkMillis = millis();
menuBlinkOn = !menuBlinkOn;
}
// CLF Auto Timer expiration
if (CLFauto && clfTimerActive && clfTsec > 0) {
if (millis() - clfTimerStart >= (unsigned long)clfTsec * 1000) {
clfTimerActive = false;
clfpushed = LOW;
}
}
// Blower Timer expiration
if (blowerTimerActive && blowTsec > 0) {
if (millis() - blowerTimerStart >= (unsigned long)blowTsec * 1000) {
blowerTimerActive = false;
blowpushed = LOW;
}
}
// Safety interlock: if UV is ON, turn CLF OFF
if (uvpushed == HIGH) {
clfTimerActive = false;
clfpushed = LOW;
}
EEPROM.get(EE_ADDR, value);
// Serial.println(value);
bool door1relayval = digitalRead(door1);
bool door2relayval = digitalRead(door2);
bool door3relayval = digitalRead(door3);
if (uvpause == 1 && Emergencepushed == 0 && door1relayval == HIGH && door2relayval == HIGH && door3relayval == HIGH) {
// Serial.print(" count ");
countup();
}
else if (uvpause == 0 && currentMenu == 0 && Emergencepushed == 0 ) {
// bool door3val = ( analogRead( A6 ) > 512 ) ;
// door2val = digitalRead(door2sen);
// Serial.println("door2val:");
noncount();
}
Emergencebutval = 1 - digitalRead(Emergence); //reading emergence
bool emgPressedThisTurn = false;
if (currentMenu == 0) {
if (Emergencebutval == HIGH && EmergencelightON == LOW && (millis() - lastMenuTransitionTime > 300)) {
Emergencepushed = 1 - Emergencepushed;
if (Emergencepushed == HIGH) {
triggerEmergencyReset();
} else {
didMyOneTimeAction = true;
digitalWrite(door1, HIGH);
delay(1000);
digitalWrite(door2, HIGH);
delay(1000);
digitalWrite(door3, HIGH);
}
delay(100);
}
EmergencelightON = Emergencebutval;
} else {
// In menu, emergency button is used as a back button
if (Emergencebutval == HIGH && EmergencelightON == LOW) {
emgPressedThisTurn = true;
delay(100);
}
EmergencelightON = Emergencebutval;
}
if (Emergencepushed == LOW) {
lcd1.display();
lcd2.display();
lcd3.display();
lcd1.backlight();
lcd2.backlight();
lcd3.backlight();
static unsigned long lastTopLineUpdate = 0;
if (uvpushed == HIGH || doorlookbool == true) {
if (millis() - lastTopLineUpdate >= 1000) {
lastTopLineUpdate = millis();
drawTopLine();
}
}
//Serial.println(hourmeter.getCurrent());
//hourmeter.run();
//countup();
if (timer) {
uvtDown.run();
}
menubuttonState = 1 - digitalRead(menubut);
door1val = digitalRead(door1sen);
door2val = digitalRead(door2sen);
// door3val = analogRead(door3sen);
if (analogRead(door3sen) > 0) {
door3val = 1;
}
else {
door3val = 0;
}
// bool door3val = ( analogRead( A6 ) > 512 ) ;
updateBuzzer();
// Post-close Door Lock Timer logic
if (doorlock && postCloseLockActive) {
if (millis() - postCloseLockStart >= (unsigned long)dlockTsec * 1000) {
postCloseLockActive = false;
doorlookbool = false;
clearAllLcds();
drawTopLine();
updatetxtoutside();
} else {
doorlookbool = true;
}
} else {
postCloseLockActive = false;
doorlookbool = false;
}
door1butval = 1 - digitalRead(door1but);
door2butval = 1 - digitalRead(door2but);
door3butval = 1 - digitalRead(door3but);
uvbutval = 1 - digitalRead(uvbut);
clfbutval = 1 - digitalRead(clfbut);
blowbutval = 1 - digitalRead(blowbut);
// Serial.println("door3butval :");
// Serial.println(door3butval);
// Serial.println("door2butval :");
// Serial.println(door2butval);
// Serial.println("door1butval :");
// Serial.println(door1butval);
// door1lightON
// Serial.println(door1lightON);
// Menu inactive timeout logic (2 minutes)
if (currentMenu == 0) {
lastMenuActivity = millis();
} else {
if (menubuttonState == HIGH || uvbutval == HIGH || clfbutval == HIGH || blowbutval == HIGH) {
lastMenuActivity = millis();
}
if (millis() - lastMenuActivity >= 120000) {
if (currentMenu == 10) {
EEPROM.update(100 + cursorpt, (int)alphabet[alphabetIndex]);
}
currentMenu = 0;
passNo = 0;
stepNo = 0;
stepNoo = 0;
stepNo3 = 0;
inEditMode = false;
popupSetTimeSelected = true;
digitIndex = 0;
didMyOneTimeAction = true;
lcd1.noBlink(); lcd2.noBlink(); lcd3.noBlink();
lcd1.noCursor(); lcd2.noCursor(); lcd3.noCursor();
}
}
int uvval = bitRead(PORTD, uv);
//// Menu ////
if (menubuttonState == HIGH && menulightON == LOW && uvval == LOW && (millis() - lastMenuTransitionTime > 300)) {
if (currentMenu == 0) {
currentMenu = 1;
stepNo = 0;
stepNoo = 0;
stepNo3 = 0;
inEditMode = false;
popupSetTimeSelected = true;
digitIndex = 0;
menupushed = 1 - menupushed;
delay(100);
} else {
if (currentMenu == 8) {
EEPROM.update(100 + cursorpt, (int)alphabet[alphabetIndex]);
}
currentMenu = 0;
stepNo = 0;
stepNoo = 0;
stepNo3 = 0;
inEditMode = false;
popupSetTimeSelected = true;
digitIndex = 0;
didMyOneTimeAction = true;
menupushed = 1 - menupushed;
delay(100);
}
}
menulightON = menubuttonState;
if (currentMenu == 0) { //home page
if (didMyOneTimeAction == true) {
didMyOneTimeAction = false;
lcd1.clear();
lcd2.clear();
lcd3.clear();
resetDoorFlags();
}
if (rst == true) {
Countsec = 0;
Countmin = 0;
Counthour = 0;
rst = false;
}
//// Screen text refresh ////
if (door1val == HIGH && door2val == HIGH && door3val == HIGH) { //both are open
if (HHH == 0) {
clearAllLcds();
resetDoorFlags();
HHH = 1;
drawTopLine();
printAllLcds(0, 1, F("Sensors Failed"));
}
UV_OFF();
}
else if (door1val == HIGH && door2val == LOW && door3val == LOW) { //Door1 is open
if (HLL == 0) {
clearAllLcds();
resetDoorFlags();
HLL = 1;
drawTopLine();
printLcd(lcd1, 0, 1, F("Sensor Failed 1"));
printLcd(lcd2, 1, 1, F("Other door open"));
printLcd(lcd3, 1, 1, F("Other door open"));
}
UV_OFF();
}
else if (door1val == LOW && door2val == HIGH && door3val == LOW) { //Door2 is open
if (LHL == 0) {
clearAllLcds();
resetDoorFlags();
LHL = 1;
drawTopLine();
printLcd(lcd1, 1, 1, F("Other door open"));
printLcd(lcd2, 0, 1, F("Sensor Failed 2"));
printLcd(lcd3, 1, 1, F("Other door open"));
}
UV_OFF();
}
else if (door1val == LOW && door2val == LOW && door3val == HIGH) { //Door2 is open
if (LLH == 0) {
clearAllLcds();
resetDoorFlags();
LLH = 1;
drawTopLine();
printLcd(lcd1, 1, 1, F("Other door open"));
printLcd(lcd2, 1, 1, F("Other door open"));
printLcd(lcd3, 0, 1, F("Sensor Failed 3"));
}
UV_OFF();
}
else if (door1val == LOW && door2val == HIGH && door3val == HIGH) { //Door2 is open
if (LHH == 0) {
clearAllLcds();
resetDoorFlags();
LHH = 1;
drawTopLine();
printLcd(lcd1, 1, 1, F("Other door open"));
printLcd(lcd2, 0, 1, F("Sensor Failed 2"));
printLcd(lcd3, 0, 1, F("Sensor Failed 3"));
}
UV_OFF();
}
else if (door1val == HIGH && door2val == HIGH && door3val == LOW) { //Door2 is open
if (HHL == 0) {
clearAllLcds();
resetDoorFlags();
HHL = 1;
drawTopLine();
printLcd(lcd1, 0, 1, F("Sensor Failed 1"));
printLcd(lcd2, 0, 1, F("Sensor Failed 2"));
printLcd(lcd3, 1, 1, F("Other door open"));
}
UV_OFF();
}
else if (door1val == HIGH && door2val == LOW && door3val == HIGH) { //Door2 is open
if (HLH == 0) {
clearAllLcds();
resetDoorFlags();
HLH = 1;
drawTopLine();
printLcd(lcd1, 0, 1, F("Sensor Failed 1"));
printLcd(lcd2, 1, 1, F("Other door open"));
printLcd(lcd3, 0, 1, F("Sensor Failed 3"));
}
UV_OFF();
}
else { //both are closed
if (LLL == 0) {
clearAllLcds();
resetDoorFlags();
LLL = 1;
drawTopLine();
updatetxtoutside();
}
////// uv light button //////
if (uvbutval == HIGH && uvlightON == LOW) {
uvpushed = 1 - uvpushed;
delay(100);
drawTopLine();
}
uvlightON = uvbutval;
bool door1relayval = digitalRead(door1);
bool door2relayval = digitalRead(door2);
bool door3relayval = digitalRead(door3);
if (uvpushed == HIGH) {
if (uvpushed == 1 && door1relayval == HIGH && door2relayval == HIGH && door3relayval == HIGH) {
digitalWrite(uv, HIGH);
if (uvManualMode) {
uvpause = 1;
} else {
// Run UV on a countdown timer only if timer (Tmr) is ON
if (timer) {
if (uvtDown.isStopped()) {
uvtDown.start();
}
}
uvpause = 1;
}
}
} else {
UV_OFF();
}
// lcd1.setCursor(3, 1);
// lcd1.print(F("Press open"));
// lcd2.setCursor(3, 1);
// lcd2.print(F("Press open"));
}
bool door1relayval = digitalRead(door1);
bool door2relayval = digitalRead(door2);
bool door3relayval = digitalRead(door3);
clfblow();
if (uvbutval == HIGH && uvlightON == LOW) {
uvpushed = 1 - uvpushed;
//uvpushed = 0;
delay(100);
}
uvlightON = uvbutval;
// Serial.print("oneTimeAfterDoorClose1 ");
// Serial.println(oneTimeAfterDoorClose1);
// Serial.print("door1first ");
// Serial.println(door1first);
// Serial.print("uvpushed ");
// Serial.println(uvpushed);
if (door1butval == HIGH && door1lightON == LOW && doorlookbool == false) {
door1pushed = 1 - door1pushed;
delay(100);
}
door1lightON = door1butval;
if (door2butval == HIGH && door2lightON == LOW && doorlookbool == false) {
door2pushed = 1 - door2pushed;
delay(100);
}
door2lightON = door2butval;
if (door3butval == HIGH && door3lightON == LOW && doorlookbool == false) {
door3pushed = 1 - door3pushed;
delay(100);
}
door3lightON = door3butval;
//// door one open logic ////
if (door1pushed == HIGH && door2relayval == HIGH && door3relayval == HIGH && doorlookbool == false) {
Serial.println("lol");
if (door1first == LOW) {
UV_OFF();
printLcd(lcd1, 1, 1, F(" Go Door Open "));
printLcd(lcd2, 1, 1, F("Wait Door Close"));
printLcd(lcd3, 1, 1, F("Wait Door Close"));
digitalWrite(door1, LOW);
if (clfpushed == LOW) {
clfpushed = HIGH;
}
if (!isStatic && blowpushed == LOW) {
blowpushed = HIGH;
}
//digitalWrite(blow, HIGH);
oneTimeAfterDoorClose1 = 0;
door1first = HIGH;
}
Count = 0;
while (Count < dlockTsec) // if is not opened
{
senoropendoor1 = LOW;
checkEmergencyButton();
if (Emergencepushed == LOW) {
unsigned long currentTime = millis();
updateDoorStates();
clfblow();
// delay(1000);
if (door1val == HIGH) // door1 opened
{
Serial.println("while1");
Dooor1 = 0; // door1 opened
break;
} else {
// Count++;
if (currentTime - previousTime >= eventInterval) {
Count++;
previousTime = currentTime;
}
Dooor1 = 1; // door1 closed
}
}
else {
emer();
break;
}
} /* while(Count < 20) loop ends */
if (Dooor1 == 0) // door1 opened
{
Count = 0;
while (Count < 40) { // door1 opened, loop until door1 closed
checkEmergencyButton();
if (Emergencepushed == LOW) {
unsigned long currentTime = millis();
updateDoorStates();
clfblow();
if (door1val == LOW) // door1 CLOSEed
{
Dooor1 = 0; // door1 closed
break;
} else {
if (currentTime - previousTime >= eventInterval) {
Count++;
previousTime = currentTime;
}
Dooor1 = 1; // door1 opened
}
} else {
emer();
break;
}
}
if (Dooor1 == 0) {
// M1 = ON; // lock magnet1
digitalWrite(door1, HIGH);
senoropendoor1 = HIGH;
Serial.println(931);
// digitalWrite(clf, LOW);
// digitalWrite(blow, LOW);
door1pushed = LOW;
door1first = LOW;
lcd1.clear();
lcd2.clear();
lcd3.clear();
resetDoorFlags();
} else {
while (door1val) {
checkEmergencyButton();
if (Emergencepushed == LOW) {
clfblow();
updateDoorStates();
delay(10);
} else {
emer();
break;
}
}
// M1 = ON; // lock magnet1
digitalWrite(door1, HIGH);
senoropendoor1 = HIGH;
Serial.println(970);
// digitalWrite(clf, LOW);
// digitalWrite(blow, LOW);
door1pushed = LOW;
door1first = LOW;
lcd1.clear();
lcd2.clear();
lcd3.clear();
resetDoorFlags();
}
}
else // door2 closed
{
// M1 = ON; // lock magnet1
digitalWrite(door1, HIGH);
// senoropendoor1 = HIGH;
Serial.println(984);
// digitalWrite(clf, LOW);
// digitalWrite(blow, LOW);
door1pushed = LOW;
door1first = LOW;
lcd1.clear();
lcd2.clear();
lcd3.clear();
resetDoorFlags();
}
}
else {
door1first = LOW;
digitalWrite(door1, HIGH);
if (oneTimeAfterDoorClose1 == 0) {
Serial.println("oneTimeAfterDoorClose");
Serial.println(senoropendoor1);
door1first = LOW;
// door1first = HIGH;
if (timer == true && senoropendoor1 == true) {
uvpushed = 1;
}
if (doorlock == true && senoropendoor1 == true) {
postCloseLockActive = true;
postCloseLockStart = millis();
doorlookbool = true;
}
if (CLFauto && senoropendoor1 == true) {
clfTimerActive = true;
clfTimerStart = millis();
clfpushed = HIGH;
} else {
if (clfpushed == HIGH) {
clfpushed = LOW;
}
}
if (!isStatic && Blowerauto && senoropendoor1 == true) {
blowerTimerActive = true;
blowerTimerStart = millis();
blowpushed = HIGH;
} else {
if (blowpushed == HIGH) {
blowpushed = LOW;
}
}
oneTimeAfterDoorClose1 = 1;
}
}
//// door two open logic ////
if (door2pushed == HIGH && door1relayval == HIGH && door3relayval == HIGH && doorlookbool == false) {
// digitalWrite(door2, LOW);
if (door2first == LOW) {
UV_OFF();
printLcd(lcd1, 1, 1, F("Wait Door Close"));
printLcd(lcd2, 1, 1, F(" Go Door Open "));
printLcd(lcd3, 1, 1, F("Wait Door Close"));
digitalWrite(door2, LOW);
if (clfpushed == LOW) {
clfpushed = HIGH;
}
if (!isStatic && blowpushed == LOW) {
blowpushed = HIGH;
}
door2first = HIGH;
oneTimeAfterDoorClose2 = 0;
}
Count = 0;
while (Count < dlockTsec) {
checkEmergencyButton();
if (Emergencepushed == LOW) {
unsigned long currentTime = millis();
updateDoorStates();
clfblow();
if (door2val == HIGH) // door1 opened
{
Dooor2 = 0; // door1 opened
break;
} else {
if (currentTime - previousTime >= eventInterval) {
Count++;
previousTime = currentTime;
}
Dooor2 = 1; // door1 closed
}
} else {
emer();
break;
}
Serial.println("while");
} /* while(Count < 20) loop ends */
if (Dooor2 == 0) // door1 opened
{
Count = 0;
while (Count < 40) { // door1 opened, loop until door1 closed
checkEmergencyButton();
if (Emergencepushed == LOW) {
unsigned long currentTime = millis();
updateDoorStates();
clfblow();
if (door2val == LOW) // door1 CLOSEed
{
Dooor2 = 0; // door1 closed
break;
} else {
if (currentTime - previousTime >= eventInterval) {
Count++;
previousTime = currentTime;
}
Dooor2 = 1; // door1 opened
}
}
else {
emer();
break;
}
}
if (Dooor2 == 0) {
// M1 = ON; // lock magnet1
digitalWrite(door2, HIGH);
senoropendoor2 = HIGH;
//digitalWrite(clf, LOW);
//digitalWrite(blow, LOW);
door2pushed = LOW;
door2first = LOW;
lcd1.clear();
lcd2.clear();
lcd3.clear();
resetDoorFlags();
} else {
while (door2val) {
Emergencebutval = 1 - digitalRead(Emergence);
if (Emergencebutval == HIGH && EmergencelightON == LOW) {
Emergencepushed = 1 - Emergencepushed;
delay(100);
}
EmergencelightON = Emergencebutval;
if (Emergencepushed == LOW) {
clfblow();
updateDoorStates();
delay(10);
} else {
emer();
break;
}
}
// M1 = ON; // lock magnet1
digitalWrite(door2, HIGH);
senoropendoor2 = HIGH;
//digitalWrite(clf, LOW);
//digitalWrite(blow, LOW);
door2pushed = LOW;
door2first = LOW;
lcd1.clear();
lcd2.clear();
lcd3.clear();
resetDoorFlags();
}
}
else // door2 closed
{
// M1 = ON; // lock magnet1
digitalWrite(door2, HIGH);
// senoropendoor2 = HIGH;
// digitalWrite(clf, LOW);
// digitalWrite(blow, LOW);
door2pushed = LOW;
door2first = LOW;
lcd1.clear();
lcd2.clear();
lcd3.clear();
resetDoorFlags();
}
}
else {
door2first = LOW;
digitalWrite(door2, HIGH);
if (oneTimeAfterDoorClose2 == 0) {
if (timer == true && senoropendoor2 == HIGH) {
uvpushed = 1;
}
if (doorlock == true && senoropendoor2 == HIGH) {
postCloseLockActive = true;
postCloseLockStart = millis();
doorlookbool = true;
}
if (CLFauto && senoropendoor2 == HIGH) {
clfTimerActive = true;
clfTimerStart = millis();
clfpushed = HIGH;
} else {
if (clfpushed == HIGH) {
clfpushed = LOW;
}
}
if (!isStatic && Blowerauto && senoropendoor2 == HIGH) {
blowerTimerActive = true;
blowerTimerStart = millis();
blowpushed = HIGH;
} else {
if (blowpushed == HIGH) {
blowpushed = LOW;
}
}
oneTimeAfterDoorClose2 = 1;
}
}
//// door three open logic ////
if (door3pushed == HIGH && door1relayval == HIGH && door2relayval == HIGH && doorlookbool == false) {
// digitalWrite(door3, LOW);
if (door3first == LOW) {
UV_OFF();
printLcd(lcd1, 1, 1, F("Wait Door Close"));
printLcd(lcd2, 1, 1, F("Wait Door Close"));
printLcd(lcd3, 1, 1, F(" Go Door Open "));
digitalWrite(door3, LOW);
if (clfpushed == LOW) {
clfpushed = HIGH;
}
if (!isStatic && blowpushed == LOW) {
blowpushed = HIGH;
}
door3first = HIGH;
oneTimeAfterDoorClose3 = 0;
}
Count = 0;
while (Count < dlockTsec) {
checkEmergencyButton();
if (Emergencepushed == LOW) {
unsigned long currentTime = millis();
updateDoorStates();
clfblow();
if (door3val == HIGH) // door1 opened
{
Dooor3 = 0; // door1 opened
break;
} else {
if (currentTime - previousTime >= eventInterval) {
Count++;
previousTime = currentTime;
}
Dooor3 = 1; // door1 closed
}
} else {
emer();
break;
}
Serial.println("while");
} /* while(Count < 20) loop ends */
if (Dooor3 == 0) // door1 opened
{
Count = 0;
while (Count < 40) { // door1 opened, loop until door1 closed
checkEmergencyButton();
if (Emergencepushed == LOW) {
unsigned long currentTime = millis();
updateDoorStates();
clfblow();
if (door3val == LOW) // door1 CLOSEed
{
Dooor3 = 0; // door1 closed
break;
} else {
if (currentTime - previousTime >= eventInterval) {
Count++;
previousTime = currentTime;
}
Dooor3 = 1; // door1 opened
}
}
else {
emer();
break;
}
}
if (Dooor3 == 0) {
// M1 = ON; // lock magnet1
digitalWrite(door3, HIGH);
senoropendoor3 = true;
//digitalWrite(clf, LOW);
//digitalWrite(blow, LOW);
door3pushed = LOW;
door3first = LOW;
lcd1.clear();
lcd2.clear();
lcd3.clear();
resetDoorFlags();
} else {
while (door3val) {
Emergencebutval = 1 - digitalRead(Emergence);
if (Emergencebutval == HIGH && EmergencelightON == LOW) {
Emergencepushed = 1 - Emergencepushed;
delay(100);
}
EmergencelightON = Emergencebutval;
if (Emergencepushed == LOW) {
clfblow();
updateDoorStates();
delay(10);
} else {
emer();
break;
}
}
// M1 = ON; // lock magnet1
digitalWrite(door3, HIGH);
senoropendoor3 = true;
//digitalWrite(clf, LOW);
//digitalWrite(blow, LOW);
door3pushed = LOW;
door3first = LOW;
lcd1.clear();
lcd2.clear();
lcd3.clear();
resetDoorFlags();
}
}
else // door2 closed
{
// M1 = ON; // lock magnet1
digitalWrite(door3, HIGH);
// digitalWrite(clf, LOW);
// digitalWrite(blow, LOW);
door3pushed = LOW;
door3first = LOW;
lcd1.clear();
lcd2.clear();
lcd3.clear();
resetDoorFlags();
}
}
else {
door3first = LOW;
digitalWrite(door3, HIGH);
if (oneTimeAfterDoorClose3 == 0) {
if (timer == true && senoropendoor3 == true) {
uvpushed = 1;
}
if (doorlock == true && senoropendoor3 == true) {
postCloseLockActive = true;
postCloseLockStart = millis();
doorlookbool = true;
}
if (CLFauto && senoropendoor3 == true) {
clfTimerActive = true;
clfTimerStart = millis();
clfpushed = HIGH;
} else {
if (clfpushed == HIGH) {
clfpushed = LOW;
}
}
if (!isStatic && Blowerauto && senoropendoor3 == true) {
blowerTimerActive = true;
blowerTimerStart = millis();
blowpushed = HIGH;
} else {
if (blowpushed == HIGH) {
blowpushed = LOW;
}
}
oneTimeAfterDoorClose3 = 1;
}
}
}
static int lastMenu = -1;
if (currentMenu != lastMenu) {
lastMenu = currentMenu;
lastMenuTransitionTime = millis();
inEditMode = false;
popupSetTimeSelected = true;
digitIndex = 0;
didMyOneTimeAction5 = false; // for Set Name (page 7)
if (currentMenu == 2) {
didMyOneTimeAction2 = false;
}
if (currentMenu == 4) {
menuCursorOnRight = !uvManualMode;
} else if (currentMenu == 6) {
menuCursorOnRight = doorlock;
} else if (currentMenu == 8) {
menuCursorOnRight = Blowerauto;
} else if (currentMenu == 11) {
menuCursorOnRight = isStatic;
} else if (currentMenu == 5 || currentMenu == 7 || currentMenu == 9) {
menuCursorOnRight = false;
inEditMode = false;
}
if ((currentMenu >= 4 && currentMenu <= 9) || currentMenu == 11) {
clearAllLcds();
if (currentMenu == 4) drawUvModePage();
else if (currentMenu == 5) {
printAllLcds(0, 0, F("Set UV Time: "));
}
else if (currentMenu == 6) drawDlModePage();
else if (currentMenu == 7) {
printAllLcds(0, 0, F("Set DL Time: "));
}
else if (currentMenu == 8) drawBlowerModePage();
else if (currentMenu == 9) {
printAllLcds(0, 0, F("Set Blower Time:"));
}
else if (currentMenu == 11) drawTypePage();
}
}
//// Menu Screen ////
if (currentMenu == 1 && uvval == 0) { //menu password page
if (didMyOneTimeAction == false) {
didMyOneTimeAction = true;
lcd1.clear();
lcd2.clear();
lcd3.clear();
}
if (emgPressedThisTurn) {
currentMenu = 0;
passNo = 0;
stepNo = 0;
stepNoo = 0;
stepNo3 = 0;
didMyOneTimeAction = true;
lcd1.noBlink(); lcd2.noBlink(); lcd3.noBlink();
lcd1.noCursor(); lcd2.noCursor(); lcd3.noCursor();
} else {
if (uvbutval == HIGH) {
if (passNo == 0) {
passNo++;
Serial.print(stepNo);
lcd1.noBlink();
lcd2.noBlink();
lcd3.noBlink();
delay(100);
}
}
if (clfbutval == HIGH) {
if (passNo == 1) {
passNo++;
}
}
if (blowbutval == HIGH) {
if (passNo == 2) {
passNo++;
delay(100);
}
}
if (passNo == 3) {
// lcd.clear();
currentMenu = 2;
passNo = 0;
}
printAllLcds(0, 0, F("Password Please:"));
didMyOneTimeAction2 = false;
}
}
if (currentMenu == 2 && uvval == 0) { //menu first page
if (didMyOneTimeAction2 == false) {
didMyOneTimeAction2 = true;
clearAllLcds();
drawMenu2();
}
//nextButtonState = digitalRead(uv);
if (emgPressedThisTurn) {
if (stepNo > 0) {
stepNo--;
lcd1.noBlink(); lcd2.noBlink(); lcd3.noBlink();
clearAllLcds();
drawMenu2();
} else {
currentMenu = 0;
passNo = 0;
stepNo = 0;
stepNoo = 0;
stepNo3 = 0;
didMyOneTimeAction = true;
lcd1.noBlink(); lcd2.noBlink(); lcd3.noBlink();
lcd1.noCursor(); lcd2.noCursor(); lcd3.noCursor();
}
} else if (uvbutval == HIGH) {
stepNo++;
Serial.print(stepNo);
lcd1.noBlink();
lcd2.noBlink();
lcd3.noBlink();
delay(100);
if (stepNo == 2) {
// lcd.clear();
currentMenu = 4;
stepNo = 0;
} else {
clearAllLcds();
drawMenu2();
}
}
dmy();
didMyOneTimeAction3 = false;
}
if (currentMenu == 4 && uvval == 0) {
bool oldManualMode = uvManualMode;
handleGenericModePage(uvManualMode, EE_ADDR_UV_MANUAL, 6, 5, drawUvModePage, 2, 1, emgPressedThisTurn, true);
if (uvManualMode != oldManualMode) {
timer = !uvManualMode;
saveSettingsToEEPROM();
}
}
if (currentMenu == 5 && uvval == 0) {
int oldUvTime = uvtTmin;
handleGenericTimePage(uvtTmin, EE_ADDR_UV_TIME, 6, drawUvTimePage, 4, 0, emgPressedThisTurn);
if (uvtTmin != oldUvTime) {
UVThour = uvtTmin / 60;
UVTmint = uvtTmin % 60;
EEPROM.update(EE_ADDR_UV_HOUR, UVThour);
EEPROM.update(EE_ADDR_UV_MIN, UVTmint);
if (!uvtDown.isStopped()) {
uvtDown.stop();
}
uvtDown.setCounter(UVThour, UVTmint, UVTsec, uvtDown.COUNT_DOWN, uvtDownComplete, 0);
}
}
if (currentMenu == 6 && uvval == 0) {
int prevMenu = uvManualMode ? 4 : 5;
handleGenericModePage(doorlock, EE_ADDR_DOORLOCK, 11, 7, drawDlModePage, prevMenu, 0, emgPressedThisTurn, false);
}
if (currentMenu == 7 && uvval == 0) {
handleGenericTimePage(dlockTsec, EE_ADDR_DLOCK_TIME, 11, drawLockTimePage, 6, 0, emgPressedThisTurn);
}
if (currentMenu == 11 && uvval == 0) {
handleGenericModePage(isStatic, EE_ADDR_IS_STATIC, 8, 10, drawTypePage, doorlock ? 7 : 6, 0, emgPressedThisTurn, false);
}
if (currentMenu == 8 && uvval == 0) {
handleGenericModePage(Blowerauto, EE_ADDR_BLOWER_AUTO, 10, 9, drawBlowerModePage, 11, 0, emgPressedThisTurn, false);
}
if (currentMenu == 9 && uvval == 0) {
handleGenericTimePage(blowTsec, EE_ADDR_BLOWER_SEC, 10, drawBlowerTimePage, 8, 0, emgPressedThisTurn);
}
if (currentMenu == 10 && uvval == 0) { //menu fifth page (set name)
if (didMyOneTimeAction5 == false) {
didMyOneTimeAction5 = true;
cursorpt = 0;
alphabetIndex = 43; // space
for (int i = 0; i < 12; i++) {
EEPROM.update(i + 100, (int)' ');
}
lcd1.clear();
lcd2.clear();
lcd3.clear();
updatetxt();
printAllLcds(0, 0, F("Set name: "));
}
// Blinking cursor logic synchronized with global menuBlinkOn
char blinkChar = menuBlinkOn ? alphabet[alphabetIndex] : '_';
lcd1.setCursor(cursorpt + 2, 1);
lcd1.print(blinkChar);
lcd2.setCursor(cursorpt + 2, 1);
lcd2.print(blinkChar);
lcd3.setCursor(cursorpt + 2, 1);
lcd3.print(blinkChar);
if (emgPressedThisTurn) {
if (cursorpt > 0) {
// Save current selection at current cursor position before moving back
EEPROM.update(100 + cursorpt, (int)alphabet[alphabetIndex]);
// Move cursor back
cursorpt--;
// Load character at the new cursor position to update alphabetIndex
char prevChar = EEPROM.read(100 + cursorpt);
alphabetIndex = 43; // default to space
for (int i = 0; i < 44; i++) {
if (alphabet[i] == prevChar) {
alphabetIndex = i;
break;
}
}
// Update screen display
updatetxt();
} else {
// If cursorpt is 0, go back to Menu 11 (Set Type) or Menu 9 (Set Blower Time) or Menu 8 (Set Blower Mode)
if (isStatic) {
currentMenu = 11;
} else {
currentMenu = Blowerauto ? 9 : 8;
}
inEditMode = false;
popupSetTimeSelected = true;
}
} else {
bool doorPressed = checkAnyDoorButtonPressed();
if (doorPressed) {
while (digitalRead(door1but) == LOW || digitalRead(door2but) == LOW || digitalRead(door3but) == LOW) {
delay(10);
}
delay(50);
EEPROM.update(100 + cursorpt, (int)alphabet[alphabetIndex]);
cursorpt = 0;
currentMenu = 2;
didMyOneTimeAction2 = false;
clearAllLcds();
} else {
forwButFun();
upButFun();
downButFun();
}
}
}
}
else { //on emergence
digitalWrite(door1, LOW);
digitalWrite(door2, LOW);
digitalWrite(door3, LOW);
digitalWrite(uv, LOW);
digitalWrite(clf, LOW);
digitalWrite(blow, LOW);
triggerEmergencyReset();
// lcd1.noDisplay();
// lcd2.noDisplay();
// lcd1.noBacklight();
// lcd2.noBacklight();
printAllLcds(0, 0, F(" EMERGENCY "));
printAllLcds(0, 1, F(" "));
Serial.println("else");
}
}
//// functions ////
void resetDoorFlags() {
HHH = 0;
HLL = 0;
LHL = 0;
LLH = 0;
LHH = 0;
HHL = 0;
HLH = 0;
LLL = 0;
}
void triggerEmergencyReset() {
digitalWrite(uv, LOW);
uvtDown.stop();
uvtDown.setCounter(UVThour, UVTmint, UVTsec, uvtDown.COUNT_DOWN, uvtDownComplete, 0);
lastRtcSec = 0;
uvpause = 0;
uvpushed = 0;
doorlookbool = false;
postCloseLockActive = false;
clfpushed = LOW;
blowpushed = LOW;
digitalWrite(clf, LOW);
digitalWrite(blow, LOW);
currentMenu = 0;
passNo = 0;
stepNo = 0;
stepNoo = 0;
stepNo3 = 0;
inEditMode = false;
popupSetTimeSelected = true;
digitIndex = 0;
didMyOneTimeAction = true;
lcd1.noBlink(); lcd2.noBlink(); lcd3.noBlink();
lcd1.noCursor(); lcd2.noCursor(); lcd3.noCursor();
}
void drawTopLine() {
char hourMeterBuf[16];
sprintf(hourMeterBuf, "%04lu:%02lu:%02lu", (unsigned long)Counthour, (unsigned long)Countmin, (unsigned long)Countsec);
lcd1.setCursor(0, 0);
lcd1.print("UV: ");
lcd1.print(hourMeterBuf);
lcd1.print(timer ? "Tr" : " ");
lcd2.setCursor(0, 0);
lcd2.print("UV: ");
lcd2.print(hourMeterBuf);
lcd2.print(timer ? "Tr" : " ");
lcd3.setCursor(0, 0);
lcd3.print("UV: ");
lcd3.print(hourMeterBuf);
lcd3.print(timer ? "Tr" : " ");
if (doorlookbool) {
char countdownBuf[17];
unsigned long remaining = 0;
if (postCloseLockActive) {
unsigned long elapsed = millis() - postCloseLockStart;
if (elapsed < (unsigned long)dlockTsec * 1000) {
remaining = ((unsigned long)dlockTsec * 1000 - elapsed) / 1000;
}
}
unsigned long remHours = remaining / 3600;
unsigned long remMinutes = (remaining % 3600) / 60;
unsigned long remSeconds = remaining % 60;
sprintf(countdownBuf, " Dlock %02d:%02d:%02d ", (int)remHours, (int)remMinutes, (int)remSeconds);
printAllLcdsStr(0, 1, countdownBuf);
}
}
void drawMenu2() {
bool blinkVal = menuBlinkOn;
char rstChar = (stepNo == 0 && !blinkVal) ? ' ' : (rst ? 'Y' : 'N');
char bzStr[4];
if (stepNo == 1 && !blinkVal) {
strcpy(bzStr, " ");
} else {
strcpy(bzStr, buzzerr ? "ON " : "OFF");
}
char buf[17];
sprintf(buf, "Rst:%c Bz:%s", rstChar, bzStr);
printAllLcdsStr(0, 0, buf);
printAllLcds(0, 1, F(" ")); // clear second line
}
void print_time2() {
Serial.print("tDown: ");
//Serial.println(hourmeter.getCurrentTime());
}
void uvtprint_time2() {
Serial.print("uvtDown: ");
Serial.println(uvtDown.getCurrentTime());
}
void hourmeterComplete() {
// hourmeter.restart();
}
void uvtDownComplete() {
uvpushed = 0;
digitalWrite(uv, LOW);
uvpause = 0;
if (Blowerauto == true) {
blowpushed = LOW;
}
doorlookbool = false;
postCloseLockActive = false;
clearAllLcds();
drawTopLine();
updatetxtoutside();
// Trigger UV completion buzzer alarm
uvCompletionAlarmActive = true;
uvCompletedTime = millis();
}
void dmy() {
static bool lastBlink = true;
bool blinkChanged = (menuBlinkOn != lastBlink);
lastBlink = menuBlinkOn;
if (stepNo == 0) {
resetfn();
} else if (stepNo == 1) {
buzzerrfn();
}
if (blinkChanged) {
drawMenu2();
}
delay(10);
}
void showResetConfirmation() {
clearAllLcds();
menuCursorOnRight = false; // default to Cancel
// Wait until all buttons are released to prevent carrying over a previous press
while (digitalRead(clfbut) == LOW || digitalRead(blowbut) == LOW ||
digitalRead(door1but) == LOW || digitalRead(door2but) == LOW || digitalRead(door3but) == LOW ||
digitalRead(uvbut) == LOW) {
delay(10);
}
delay(100); // Debounce
printAllLcds(0, 0, F("Want to continue"));
printCancelOkRow();
static bool prevClf = LOW;
static bool prevBlow = LOW;
static bool prevDoor1 = LOW;
static bool prevDoor2 = LOW;
static bool prevDoor3 = LOW;
static bool prevUv = LOW;
// Initialize previous states
prevClf = (digitalRead(clfbut) == LOW);
prevBlow = (digitalRead(blowbut) == LOW);
prevDoor1 = (digitalRead(door1but) == LOW);
prevDoor2 = (digitalRead(door2but) == LOW);
prevDoor3 = (digitalRead(door3but) == LOW);
prevUv = (digitalRead(uvbut) == LOW);
while (true) {
bool clfVal = (digitalRead(clfbut) == LOW);
bool blowVal = (digitalRead(blowbut) == LOW);
bool d1Val = (digitalRead(door1but) == LOW);
bool d2Val = (digitalRead(door2but) == LOW);
bool d3Val = (digitalRead(door3but) == LOW);
bool uvVal = (digitalRead(uvbut) == LOW);
bool clfPressed = (clfVal && !prevClf);
bool blowPressed = (blowVal && !prevBlow);
bool door1Pressed = (d1Val && !prevDoor1);
bool door2Pressed = (d2Val && !prevDoor2);
bool door3Pressed = (d3Val && !prevDoor3);
bool uvPressed = (uvVal && !prevUv);
prevClf = clfVal;
prevBlow = blowVal;
prevDoor1 = d1Val;
prevDoor2 = d2Val;
prevDoor3 = d3Val;
prevUv = uvVal;
if (clfPressed || blowPressed) {
menuCursorOnRight = !menuCursorOnRight;
clearAllLcds();
printAllLcds(0, 0, F("Want to continue"));
printCancelOkRow();
delay(100);
}
if (door1Pressed || door2Pressed || door3Pressed || uvPressed) {
if (menuCursorOnRight) {
// User chose OK -> Reset UV run timer
Countsec = 0;
Countmin = 0;
Counthour = 0;
rst = false;
menuclfpushed = LOW;
// Display reset message
clearAllLcds();
printAllLcds(0, 0, F("UV Timer Reset!"));
delay(1500);
clearAllLcds();
break;
} else {
// User chose Cancel -> Do not reset
rst = false;
menuclfpushed = LOW;
// Display cancel message
clearAllLcds();
printAllLcds(0, 0, F("Reset Cancelled"));
delay(1500);
clearAllLcds();
break;
}
}
delay(10);
}
}
void resetfn() {
clfbutval = 1 - digitalRead(clfbut);
blowbutval = 1 - digitalRead(blowbut);
if (clfbutval == HIGH && menuclflightON == LOW && currentMenu == 2) {
menuclfpushed = 1 - menuclfpushed;
delay(100);
}
menuclflightON = clfbutval;
if (blowbutval == HIGH && menuclflightON == LOW && currentMenu == 2) {
menuclfpushed = 1 - menuclfpushed;
delay(100);
}
menuclflightON = blowbutval;
if (menuclfpushed == HIGH) {
showResetConfirmation();
drawMenu2();
} else {
rst = false;
}
}
void buzzerrfn() {
clfbutval = 1 - digitalRead(clfbut);
blowbutval = 1 - digitalRead(blowbut);
bool changed = false;
if (clfbutval == HIGH && menuclflightONN == LOW && currentMenu == 2) {
menuclfpusheddbr = 1 - menuclfpusheddbr;
changed = true;
delay(100);
}
menuclflightONN = clfbutval;
if (blowbutval == HIGH && menuclflightONN == LOW && currentMenu == 2) {
menuclfpusheddbr = 1 - menuclfpusheddbr;
changed = true;
delay(100);
}
menuclflightONN = blowbutval;
if (menuclfpusheddbr == HIGH) {
buzzerr = true;
} else {
buzzerr = false;
}
if (changed) {
drawMenu2();
saveSettingsToEEPROM();
}
}
void drawLockTimePage() {
bool blinkVal = menuBlinkOn;
char boxStr[17];
sprintf(boxStr, " [%d%d%d%d]s ", tempDigits[0], tempDigits[1], tempDigits[2], tempDigits[3]);
if (!blinkVal) {
boxStr[6 + digitIndex] = ' ';
}
lcd1.setCursor(0, 1); lcd1.print(boxStr);
lcd2.setCursor(0, 1); lcd2.print(boxStr);
lcd3.setCursor(0, 1); lcd3.print(boxStr);
}
void drawBlowerTimePage() {
bool blinkVal = menuBlinkOn;
char boxStr[17];
sprintf(boxStr, " [%d%d%d%d]s ", tempDigits[0], tempDigits[1], tempDigits[2], tempDigits[3]);
if (!blinkVal) {
boxStr[6 + digitIndex] = ' ';
}
printAllLcdsStr(0, 1, boxStr);
}
void drawUvTimePage() {
bool blinkVal = menuBlinkOn;
char boxStr[17];
sprintf(boxStr, " [%d%d%d%d]m ", tempDigits[0], tempDigits[1], tempDigits[2], tempDigits[3]);
if (!blinkVal) {
boxStr[6 + digitIndex] = ' ';
}
lcd1.setCursor(0, 1); lcd1.print(boxStr);
lcd2.setCursor(0, 1); lcd2.print(boxStr);
lcd3.setCursor(0, 1); lcd3.print(boxStr);
}
void drawUvModePage() {
printLcd(lcd1, 0, 0, F("Set UV Mode: "));
printLcd(lcd2, 0, 0, F("Set UV Mode: "));
printLcd(lcd3, 0, 0, F("Set UV Mode: "));
printManualAutoRow();
}
void drawDlModePage() {
printLcd(lcd1, 0, 0, F("Set DL Mode: "));
printLcd(lcd2, 0, 0, F("Set DL Mode: "));
printLcd(lcd3, 0, 0, F("Set DL Mode: "));
printManualAutoRow();
}
void drawBlowerModePage() {
printLcd(lcd1, 0, 0, F("Set Blower Mode:"));
printLcd(lcd2, 0, 0, F("Set Blower Mode:"));
printLcd(lcd3, 0, 0, F("Set Blower Mode:"));
printManualAutoRow();
}
void printStaticDynamicRow() {
if (!menuCursorOnRight) {
printAllLcds(0, 1, F("\x01 Dynamic "));
} else {
printAllLcds(0, 1, F("\x01 Static "));
}
}
void drawTypePage() {
printLcd(lcd1, 0, 0, F("Set Type: "));
printLcd(lcd2, 0, 0, F("Set Type: "));
printLcd(lcd3, 0, 0, F("Set Type: "));
printStaticDynamicRow();
}
void handleGenericModePage(bool &modeVal, int eepromAddr, int nextMenuManual, int nextMenuAuto, void (*drawFunc)(), int prevMenu, int prevStepNoo, bool emgPressed, bool activeLowVal) {
clfbutval = 1 - digitalRead(clfbut);
blowbutval = 1 - digitalRead(blowbut);
uvbutval = 1 - digitalRead(uvbut);
static bool prevClf = LOW;
static bool prevBlow = LOW;
static bool prevUv = LOW;
static int lastPage = -1;
if (currentMenu != lastPage) {
lastPage = currentMenu;
prevClf = clfbutval;
prevBlow = blowbutval;
prevUv = uvbutval;
}
bool clfPressed = (clfbutval == HIGH && prevClf == LOW);
bool blowPressed = (blowbutval == HIGH && prevBlow == LOW);
bool uvPressed = (uvbutval == HIGH && prevUv == LOW);
prevClf = clfbutval;
prevBlow = blowbutval;
prevUv = uvbutval;
bool doorPressed = checkAnyDoorButtonPressed();
if (clfPressed || blowPressed) {
menuCursorOnRight = !menuCursorOnRight;
clearAllLcds();
drawFunc();
delay(100);
return;
}
if (doorPressed) {
while (digitalRead(door1but) == LOW || digitalRead(door2but) == LOW || digitalRead(door3but) == LOW) {
delay(10);
}
delay(50);
if (!menuCursorOnRight) {
modeVal = activeLowVal;
EEPROM.update(eepromAddr, modeVal ? 1 : 0);
currentMenu = nextMenuManual;
return;
} else {
modeVal = !activeLowVal;
EEPROM.update(eepromAddr, modeVal ? 1 : 0);
currentMenu = nextMenuAuto;
return;
}
}
if (uvPressed) {
while (digitalRead(uvbut) == LOW) {
delay(10);
}
delay(50);
if (!menuCursorOnRight) {
modeVal = activeLowVal;
} else {
modeVal = !activeLowVal;
}
EEPROM.update(eepromAddr, modeVal ? 1 : 0);
currentMenu = (!menuCursorOnRight) ? nextMenuManual : nextMenuAuto;
return;
}
if (emgPressed) {
currentMenu = prevMenu;
if (prevMenu == 2) {
stepNo = prevStepNoo;
} else {
stepNoo = prevStepNoo;
}
delay(100);
return;
}
}
void handleGenericTimePage(int &targetVal, int eepromAddr, int nextMenu, void (*drawFunc)(), int prevMenu, int prevStepNoo, bool emgPressed) {
static bool lastBlink = true;
bool blinkChanged = (menuBlinkOn != lastBlink);
lastBlink = menuBlinkOn;
clfbutval = 1 - digitalRead(clfbut);
blowbutval = 1 - digitalRead(blowbut);
uvbutval = 1 - digitalRead(uvbut);
static bool prevClf = LOW;
static bool prevBlow = LOW;
static bool prevUv = LOW;
static int lastPage = -1;
if (currentMenu != lastPage) {
lastPage = currentMenu;
prevClf = clfbutval;
prevBlow = blowbutval;
prevUv = uvbutval;
}
bool clfPressed = (clfbutval == HIGH && prevClf == LOW);
bool blowPressed = (blowbutval == HIGH && prevBlow == LOW);
bool uvPressed = (uvbutval == HIGH && prevUv == LOW);
prevClf = clfbutval;
prevBlow = blowbutval;
prevUv = uvbutval;
bool doorPressed = checkAnyDoorButtonPressed();
bool changed = false;
if (!inEditMode) {
inEditMode = true;
digitIndex = 0;
int temp = targetVal;
tempDigits[0] = (temp / 1000) % 10;
tempDigits[1] = (temp / 100) % 10;
tempDigits[2] = (temp / 10) % 10;
tempDigits[3] = temp % 10;
drawFunc();
delay(100);
return;
}
if (inEditMode && doorPressed) {
while (digitalRead(door1but) == LOW || digitalRead(door2but) == LOW || digitalRead(door3but) == LOW) {
delay(10);
}
delay(50);
targetVal = tempDigits[0]*1000 + tempDigits[1]*100 + tempDigits[2]*10 + tempDigits[3];
EEPROM.put(eepromAddr, targetVal);
currentMenu = nextMenu;
inEditMode = false;
popupSetTimeSelected = true;
return;
}
if (clfPressed) {
tempDigits[digitIndex] = (tempDigits[digitIndex] + 1) % 10;
changed = true;
delay(100);
}
if (blowPressed) {
tempDigits[digitIndex] = (tempDigits[digitIndex] + 9) % 10;
changed = true;
delay(100);
}
if (uvPressed) {
delay(100);
digitIndex++;
if (digitIndex >= 4) {
while (digitalRead(uvbut) == LOW) {
delay(10);
}
delay(50);
targetVal = tempDigits[0]*1000 + tempDigits[1]*100 + tempDigits[2]*10 + tempDigits[3];
EEPROM.put(eepromAddr, targetVal);
currentMenu = nextMenu;
inEditMode = false;
popupSetTimeSelected = true;
return;
}
changed = true;
}
if (emgPressed) {
inEditMode = false;
popupSetTimeSelected = true;
currentMenu = prevMenu;
if (prevMenu == 2) {
stepNo = prevStepNoo;
} else {
stepNoo = prevStepNoo;
}
delay(100);
return;
}
if (changed || blinkChanged) {
drawFunc();
}
}
void updateBuzzer() {
if (!buzzerr) {
digitalWrite(buzzer, LOW);
return;
}
bool anyDoorOpen = (door1val == HIGH || door2val == HIGH || door3val == HIGH);
// 1. Door open alarm logic
bool doorAlarmActive = false;
if (anyDoorOpen) {
if (!doorWasOpen) {
doorOpenTime = millis();
doorWasOpen = true;
} else {
if (millis() - doorOpenTime >= 15000) {
doorAlarmActive = true;
Serial.println("Buz");
}
}
} else {
doorWasOpen = false;
}
// 2. UV Timer completion alarm logic (5 seconds = 5000 ms)
if (uvCompletionAlarmActive) {
if (millis() - uvCompletedTime >= 5000) {
uvCompletionAlarmActive = false;
}
}
// 3. Determine buzzer state
if (uvCompletionAlarmActive) {
// Pulse fast for UV timer completion alarm (e.g. 100ms ON, 100ms OFF)
if ((millis() / 100) % 2 == 0) {
digitalWrite(buzzer, HIGH);
} else {
digitalWrite(buzzer, LOW);
}
} else if (doorAlarmActive) {
// Sound continuously for door open alarm
digitalWrite(buzzer, HIGH);
} else {
digitalWrite(buzzer, LOW);
}
}
void clfblow() {
updateBuzzer();
clfbutval = 1 - digitalRead(clfbut);
blowbutval = 1 - digitalRead(blowbut);
if (clfbutval == HIGH && clflightON == LOW) {
clfpushed = 1 - clfpushed;
Serial.println("clf");
delay(100);
}
clflightON = clfbutval;
if (isStatic) {
blowpushed = LOW;
blowerTimerActive = false;
blowlightON = blowbutval;
} else {
if (blowbutval == HIGH && blowlightON == LOW) {
blowpushed = 1 - blowpushed;
if (blowpushed == HIGH) {
blowerTimerActive = true;
blowerTimerStart = millis();
} else {
blowerTimerActive = false;
}
Serial.println("blow");
delay(100);
}
blowlightON = blowbutval;
}
if (clfpushed == HIGH) {
digitalWrite(clf, HIGH);
} else {
digitalWrite(clf, LOW);
}
if (blowpushed == HIGH) {
digitalWrite(blow, HIGH);
} else {
digitalWrite(blow, LOW);
}
}
void clfblowed() {
blowbutval = 1 - digitalRead(blowbut);
if (isStatic) {
blowpushed = LOW;
blowerTimerActive = false;
blowlightON = blowbutval;
} else {
if (blowbutval == HIGH && blowlightON == LOW) {
blowpushed = 1 - blowpushed;
if (blowpushed == HIGH) {
blowerTimerActive = true;
blowerTimerStart = millis();
} else {
blowerTimerActive = false;
}
delay(100);
}
blowlightON = blowbutval;
}
if (blowpushed == HIGH) {
digitalWrite(blow, HIGH);
} else {
digitalWrite(blow, LOW);
}
}
void UV_OFF() {
digitalWrite(uv, LOW);
lastRtcSec = 0;
if (uvbutval == HIGH && uvlightON == LOW) {
uvpushed = 1 - uvpushed;
//uvpushed = 0;
delay(100);
}
uvlightON = uvbutval;
//hourmeter.pause();
bool wasRunning = (uvpause == 1);
uvpause = 0;
if (!uvtDown.isStopped()) {
uvtDown.stop();
uvtDown.setCounter(UVThour, UVTmint, UVTsec, uvtDown.COUNT_DOWN, uvtDownComplete, 0);
}
if (wasRunning && door1val == LOW && door2val == LOW && door3val == LOW) {
clearAllLcds();
drawTopLine();
updatetxtoutside();
}
}
void emer() { //emergency
digitalWrite(door1, LOW);
digitalWrite(door2, LOW);
digitalWrite(door3, LOW);
digitalWrite(uv, LOW);
digitalWrite(clf, LOW);
digitalWrite(blow, LOW);
triggerEmergencyReset();
//lcd1.noDisplay();
// lcd2.noDisplay();
// lcd1.noBacklight();
// lcd2.noBacklight();
printAllLcds(0, 0, F(" EMERGENCY "));
printAllLcds(0, 1, F(" "));
Serial.println("emer func");
Emergencebutval = 1 - digitalRead(Emergence);
if (Emergencebutval == 1) {
Emergencepushed = LOW;
didMyOneTimeAction = true;
digitalWrite(door1, HIGH);
delay(1000);
digitalWrite(door2, HIGH);
delay(1000);
digitalWrite(door3, HIGH);
}
}
void countup() {
DateTime now = rtc.now();
if (lastRtcSec == 0) {
lastRtcSec = now.unixtime();
}
if (now.unixtime() != lastRtcSec) {
uint32_t diff = now.unixtime() - lastRtcSec;
lastRtcSec = now.unixtime();
Countsec += diff;
if (Countsec >= 60) {
Countmin += Countsec / 60;
Countsec = Countsec % 60;
if (Countmin >= 60) {
Counthour += Countmin / 60;
Countmin = Countmin % 60;
if (Counthour > 9999) {
Counthour = 0;
}
}
}
drawTopLine();
}
}
void noncount() {
lastRtcSec = 0;
}
//
// clfbutval = 1 - digitalRead(clfbut);
// blowbutval = 1 - digitalRead(blowbut);
void drawMenu4Char() {
lcd1.setCursor(cursorpt + 2, 1);
lcd1.print(alphabet[alphabetIndex]);
lcd2.setCursor(cursorpt + 2, 1);
lcd2.print(alphabet[alphabetIndex]);
lcd3.setCursor(cursorpt + 2, 1);
lcd3.print(alphabet[alphabetIndex]);
}
void forwButFun() {
uvbutval = 1 - digitalRead(uvbut);
static bool prevUvVal = LOW;
if (uvbutval == HIGH && prevUvVal == LOW) {
Serial.println(cursorpt);
// Save current selection at current cursor position
EEPROM.update(100 + cursorpt, (int)alphabet[alphabetIndex]);
// Move cursor
if (cursorpt < 11) {
++cursorpt;
// Load character at the new cursor position to update alphabetIndex
char nextChar = EEPROM.read(100 + cursorpt);
alphabetIndex = 43; // default to space
for (int i = 0; i < 44; i++) {
if (alphabet[i] == nextChar) {
alphabetIndex = i;
break;
}
}
// Update screen display
updatetxt();
} else {
cursorpt = 0;
currentMenu = 2;
didMyOneTimeAction2 = false;
clearAllLcds();
}
}
prevUvVal = uvbutval;
}
void upButFun() {
static bool prevClfVal = LOW;
if (clfbutval == HIGH && prevClfVal == LOW) {
alphabetIndex++;
if (alphabetIndex >= 44) {
alphabetIndex = 0;
}
drawMenu4Char();
}
prevClfVal = clfbutval;
}
void downButFun() {
static bool prevBlowVal = LOW;
if (blowbutval == HIGH && prevBlowVal == LOW) {
alphabetIndex--;
if (alphabetIndex < 0) {
alphabetIndex = 43;
}
drawMenu4Char();
}
prevBlowVal = blowbutval;
}
void updatetxt() {
for (int i = 0; i < 12; i++) {
stringArray[i] = EEPROM.read(i + 100);
Serial.println("gg");
Serial.println(i);
Serial.println(stringArray[i]);
Serial.println("gg");
lcd1.setCursor(i + 2, 1);
lcd1.print(stringArray[i]);
lcd2.setCursor(i + 2, 1);
lcd2.print(stringArray[i]);
lcd3.setCursor(i + 2, 1);
lcd3.print(stringArray[i]);
}
}
void updatetxtoutside() {
if (doorlookbool) {
return;
}
if (EEPROM.read(100) != 255)
{
for (int i = 0; i < 12; i++) {
stringArray[i] = EEPROM.read(i + 100);
lcd1.setCursor(i + 2, 1);
lcd1.print(stringArray[i]);
lcd2.setCursor(i + 2, 1);
lcd2.print(stringArray[i]);
lcd3.setCursor(i + 2, 1);
lcd3.print(stringArray[i]);
}
}
}
// void PD_ISR() { // ISR to be get called on power-down state
// Serial.println("hi");
// //EEPROM.put(EE_ADDR, SomeVariable);
// unsigned long SomeVariable1 = 0;
// EEPROM.put(EE_ADDR, SomeVariable1);
// delay(1000);
// }
void PD_ISR() { // ISR to be get called on power-down state
//Serial.println("hi");
//EEPROM.put(EE_ADDR, SomeVariable);
// unsigned long SomeVariable1 = 0;
EEPROM.put(EE_ADDR, Count);
delay(1000);
}