#include "display_LCD.h"
#include "numeric_keypad.h"
#include "connecting_to_WiFi.h"
#include "clock_synchronization.h"
#include "real_time_clock.h"
#include "alarm_clock.h"
#include "motion_sensor.h"
#include "click_switch.h"
#include "electric_switch.h"
DisplayLCD displayLCD(23, 19, 26, 25, 33, 32);
NumericKeypad numericKeypad;
ConnectingToWiFi connectingToWiFi;
ClockSynchronization clockSynchronization;
RealTimeClock rtc;
AlarmClock alarmClock;
MotionSensor motionSensor(14);
ClickSwitch* buttom1 = new ClickSwitch(10);
ClickSwitch* buttom2 = new ClickSwitch(11);
ElectricSwitch* mainLight = new ElectricSwitch(12);
ElectricSwitch* nightLight = new ElectricSwitch(13);
ElectricSwitch* additionalLoad = new ElectricSwitch(9);
bool clockSynchOn = true;
bool alarmClockOn = true;
bool alarmMainLightOn = true;
bool alarmAdditionalLoadOn = true;
bool motionSensorOn = true;
bool motionMainLightOn = true;
bool motionNightLightOn = true;
unsigned long additionalAlarmTimer = 10;
unsigned long motionMainTimer = 10;
unsigned long motionNightTimer = 10;
int motionDayTime = 420;
int motionNightTime = 1380;
int quantArrey = 3;
int numberline = 0;
String* menuPrint;
void setup() {
rtc.initialization();
displayLCD.initialization();
menuPrint = new String[10];
for (int i = 0; i < 10; i++) {
menuPrint[i] = " ";
}
}
bool blinking() {
static bool blink = true;
static unsigned long timer = millis();
if (millis() < timer) {
timer = millis();
}
if (millis() - timer >= 300) {
timer = millis();
blink = !blink;
}
return blink;
}
/*
Отвечает за +/- в меню.
*/
int settingPlusMinus(int number, int numMin, int numMax, char symbol) {
if (symbol == 0x44) {
if (number < numMax) {
number++;
}
else {
number = numMin;
}
}
else if (symbol == 0x43) {
if (number > numMin) {
number--;
}
else {
number = numMax;
}
}
return number;
}
/*
Отвечает за +/- в меню.
*/
unsigned long settingPlusMinus(unsigned long number, int numMin, int numMax, char symbol) {
if (symbol == 0x44) {
if (number < numMax) {
number++;
}
else {
number = numMin;
}
}
else if (symbol == 0x43) {
if (number > numMin) {
number--;
}
else {
number = numMax;
}
}
return number;
}
/*
Настройка часов.
*/
void settingPrintClock(int numMenu, int zone, char symbol) {
numMenu--;
if (clockSynchOn) {
menuPrint[0] = "Watch synch On ";
}
else {
menuPrint[0] = "Watch synch Off";
}
String zoneT = String(zone, DEC);
if (blinking() && symbol == 0x23) {
zoneT = " ";
}
menuPrint[1] = String("Time zone ") + zoneT;
menuPrint[2] = "Current time set ";
if (blinking() && symbol != 0x23) {
menuPrint[numMenu] = " ";
}
quantArrey = 3;
numberline = numMenu;
}
void settingClock(char& symMenu) {
const int NUM_MAX = 3;
const int NUM_MIN = 1;
static int num = 1;
static bool copyLine = true;
static char sym = 0x00;
static int timeZone;
if (num == 1) {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
if (sym == 0x43 || sym == 0x44) {
clockSynchOn = !clockSynchOn;
num = 1;
}
settingPrintClock(num, timeZone, sym);
}
else if (num == 2) {
static int i = 0;
int CLOCK_ZONE_MAX = 12;
int CLOCK_ZONE_MIN = -12;
if (sym == 0x23) {
char number = numericKeypad.keyNumber(timeZone, CLOCK_ZONE_MIN, CLOCK_ZONE_MAX);
if (number == 0x23 || number == 0x2a) {
rtc.settingTimeZone(timeZone);
sym = 0x00;
}
}
else {
timeZone = rtc.getTimeZone();
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
timeZone = settingPlusMinus(timeZone, CLOCK_ZONE_MIN, CLOCK_ZONE_MAX, sym);
rtc.settingTimeZone(timeZone);
}
settingPrintClock(num, timeZone, sym);
}
else if (num == 3) {
static int i = 0;
const int numLine3 = 6;
String qwer;
const unsigned int numString[numLine3] = { 0, 5, 8, 12, 15, 18 };
static int clockTime[6] = { 0, 0, 0, 0, 0, 0 };
const int CLOCK_MAX[6] = { 2099, 12, 31, 23, 59, 59 };
const int CLOCK_MIN[6] = { 2000, 0, 0, 0, 0, 0 };
if (sym == 0x23 || sym == 0x44) {
if (copyLine) {
for (int i = 0; i < 6; i++) {
clockTime[i] = rtc.timeToDateTime(i);
}
copyLine = false;
}
menuPrint[3] = " . . : : ";
char number = numericKeypad.keyNumber(clockTime[i], CLOCK_MIN[i], CLOCK_MAX[i]);
if (number == 0x23) {
i++;
if (i > numLine3 - 1) {
sym = 0x00;
i = numLine3 - 1;
rtc.settingClock(clockTime);
}
}
else if (number == 0x2a) {
i--;
if (i < 0) {
sym = 0x00;
i = 0;
rtc.settingClock(clockTime);
}
}
for (int j = 0; j < numLine3; j++) {
if (j != i || blinking()) {
if (j > 0) {
if (clockTime[j] > 9){
qwer = String(clockTime[j], DEC);
}
else {
qwer = "0";
qwer += String(clockTime[j], DEC);
}
menuPrint[3].setCharAt(numString[j], qwer[0]);
menuPrint[3].setCharAt(numString[j] + 1, qwer[1]);
}
else {
if (clockTime[j] > 999){
qwer = String(clockTime[j], DEC);
}
else {
qwer = "0";
qwer += String(clockTime[j], DEC);
}
menuPrint[3].setCharAt(numString[j], qwer[0]);
menuPrint[3].setCharAt(numString[j] + 1, qwer[1]);
menuPrint[3].setCharAt(numString[j] + 2, qwer[2]);
menuPrint[3].setCharAt(numString[j] + 3, qwer[3]);
}
}
}
menuPrint[0] = " SETTING CLOCK ";
menuPrint[1] = " year.month.day - ";
menuPrint[2] = "- hour:minute:second";
quantArrey = 4;
numberline = 0;
}
else {
copyLine = true;
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
settingPrintClock(num, timeZone, sym);
}
}
if (sym == 0x2a) {
symMenu = 0x00;
}
}
/*
Настройка будильника.
*/
void settingPrintAlarms(int numMenu, char symbol, int numI = 0) {
numMenu--;
if (alarmClockOn) {
menuPrint[0] = "Alarm clock On";
}
else {
menuPrint[0] = "Alarm clock Off";
}
if (alarmMainLightOn) {
menuPrint[1] = "Main light On";
}
else {
menuPrint[1] = "Main light Off";
}
if (alarmAdditionalLoadOn) {
menuPrint[2] = "Additional load On";
}
else {
menuPrint[2] = "Additional load Off";
}
String plusString = String(additionalAlarmTimer, DEC);
if (blinking() && symbol == 0x23 && numMenu == 3) {
plusString = " ";
}
menuPrint[3] = String("Additional timer ") + plusString;
if (alarmClock.getAlarmTime(0) > 9){
plusString = String(alarmClock.getAlarmTime(0), DEC);
}
else {
plusString = "0";
plusString += String(alarmClock.getAlarmTime(0), DEC);
}
if (blinking() && symbol == 0x23 && numMenu == 4 && numI == 0) {
plusString = " ";
}
menuPrint[4] = String("Alarm clock ") + plusString;
menuPrint[4] += String(":");
if (alarmClock.getAlarmTime(1) > 9){
plusString = String(alarmClock.getAlarmTime(1), DEC);
}
else {
plusString = "0";
plusString += String(alarmClock.getAlarmTime(1), DEC);
}
if (blinking() && symbol == 0x23 && numMenu == 4 && numI == 1) {
plusString = " ";
}
menuPrint[4] += plusString;
if (blinking() && symbol != 0x23) {
menuPrint[numMenu] = " ";
}
quantArrey = 5;
numberline = numMenu;
}
void settingsAlarms (char& symMenu) {
const int NUM_MAX = 5;
const int NUM_MIN = 1;
static int i = 0;
static int num = 1;
static char sym = 0x00;
if (num == 1) {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
if (sym == 0x43 || sym == 0x44) {
alarmClockOn = !alarmClockOn;
}
}
else if (num == 2) {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
if (sym == 0x43 || sym == 0x44) {
alarmMainLightOn = !alarmMainLightOn;
}
}
else if (num == 3) {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
if (sym == 0x43 || sym == 0x44) {
alarmAdditionalLoadOn = !alarmAdditionalLoadOn;
}
}
else if (num == 4) {
const int ADDITIONAL_TIMER_MAX = 600;
const int ADDITIONAL_TIMER_MIN = 10;
if (sym == 0x23) {
int addAlarmTimer = static_cast<int> (additionalAlarmTimer);
char number = numericKeypad.keyNumber(addAlarmTimer, ADDITIONAL_TIMER_MIN, ADDITIONAL_TIMER_MAX);
additionalAlarmTimer = static_cast<unsigned long> (addAlarmTimer);
if (number == 0x23 || number == 0x2a) {
sym = 0x00;
}
}
else {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
additionalAlarmTimer = settingPlusMinus(additionalAlarmTimer, ADDITIONAL_TIMER_MIN, ADDITIONAL_TIMER_MAX, sym);
}
}
else if (num == 5) {
int numLine = 2;
const int ALARM_MAX[2] = { 23, 59};
const int ALARM_MIN[2] = { 0, 0 };
if (sym == 0x23) {
int alarmTime = alarmClock.getAlarmTime(i);
char number = numericKeypad.keyNumber(alarmTime, ALARM_MIN[i], ALARM_MAX[i]);
alarmClock.setAlarmTime(alarmTime, i);
if (number == 0x23) {
i++;
if (i > numLine - 1) {
sym = 0x00;
i = numLine - 1;
}
}
else if (number == 0x2a) {
i--;
if (i < 0) {
sym = 0x00;
i = 0;
}
}
}
else {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
if (sym == 0x44) {
if (alarmClock.getAlarmTime(0) < ALARM_MAX[0] || alarmClock.getAlarmTime(1) < ALARM_MAX[1]) {
int alarmTimeM = alarmClock.getAlarmTime(1);
alarmTimeM++;
if (alarmTimeM == 60) {
int alarmTimeH = alarmClock.getAlarmTime(0);
alarmTimeH++;
alarmTimeM = 0;
alarmClock.setAlarmTime(alarmTimeH, 0);
}
alarmClock.setAlarmTime(alarmTimeM, 1);
}
}
else if (sym == 0x43) {
if (alarmClock.getAlarmTime(0) > ALARM_MIN[0] || alarmClock.getAlarmTime(1) > ALARM_MIN[1]) {
int alarmTimeM = alarmClock.getAlarmTime(1);
alarmTimeM--;
if (alarmTimeM == -1) {
int alarmTimeH = alarmClock.getAlarmTime(0);
alarmTimeH--;
alarmTimeM = 59;
alarmClock.setAlarmTime(alarmTimeH, 0);
}
alarmClock.setAlarmTime(alarmTimeM, 1);
}
}
}
}
settingPrintAlarms(num, sym, i);
if (sym == 0x2a) {
symMenu = 0x00;
}
}
/*
Настройка датчика движения.
*/
void convertedTime(int timeDayNight[4]) {
motionDayTime = timeDayNight[2] * 60 + timeDayNight[3];
motionNightTime = timeDayNight[0] * 60 + timeDayNight[1];
}
void settingsMotionSwitchPrint(int numMenu, char symbol) {
numMenu--;
if (motionSensorOn) {
menuPrint[0] = "Motion sensor On";
}
else {
menuPrint[0] = "Motion sensor Off";
}
if (motionMainLightOn) {
menuPrint[1] = "Main light On";
}
else {
menuPrint[1] = "Main light Off";
}
String plusString = String(motionMainTimer, DEC);
if (blinking() && symbol == 0x23 && numMenu == 2) {
plusString = " ";
}
menuPrint[2] = String("MainLightTimer ") + plusString;
if (motionNightLightOn) {
menuPrint[3] = "Night light On";
}
else {
menuPrint[3] = "Night light Off";
}
plusString = String(motionNightTimer, DEC);
if (blinking() && symbol == 0x23 && numMenu == 4) {
plusString = " ";
}
menuPrint[4] = String("NightLightTimer ") + plusString;
menuPrint[5] = "Night light time";
if (blinking() && symbol != 0x23) {
menuPrint[numMenu] = " ";
}
quantArrey = 6;
numberline = numMenu;
}
void settingsMotionSwitch(char& symMenu) {
const int NUM_MAX = 6;
const int NUM_MIN = 1;
static int num = 1;
static char sym = 0x00;
if (num == 1) {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
if (sym == 0x43 || sym == 0x44) {
motionSensorOn = !motionSensorOn;
}
settingsMotionSwitchPrint(num, sym);
}
else if (num == 2) {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
if (sym == 0x43 || sym == 0x44) {
motionMainLightOn = !motionMainLightOn;
}
settingsMotionSwitchPrint(num, sym);
}
else if (num == 3) {
const int MAIN_TIMER_MAX = 600;
const int MAIN_TIMER_MIN = 10;
if (sym == 0x23) {
int motMainTimer = static_cast<int> (motionMainTimer);
char number = numericKeypad.keyNumber(motMainTimer, MAIN_TIMER_MIN, MAIN_TIMER_MAX);
motionMainTimer = static_cast<unsigned long> (motMainTimer);
if (number == 0x23 || number == 0x2a) {
sym = 0x00;
}
}
else {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
motionMainTimer = settingPlusMinus(motionMainTimer, MAIN_TIMER_MIN, MAIN_TIMER_MAX, sym);
}
settingsMotionSwitchPrint(num, sym);
}
else if(num == 4) {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
if (sym == 0x43 || sym == 0x44) {
motionNightLightOn = !motionNightLightOn;
}
settingsMotionSwitchPrint(num, sym);
}
else if (num == 5) {
const int LIGHT_TIMER_MAX = 60;
const int LIGHT_TIMER_MIN = 10;
if (sym == 0x23) {
int motNightTimer = static_cast<int> (motionNightTimer);
char number = numericKeypad.keyNumber(motNightTimer, LIGHT_TIMER_MIN, LIGHT_TIMER_MAX);
motionNightTimer = static_cast<unsigned long> (motNightTimer);
if (number == 0x23 || number == 0x2a) {
sym = 0x00;
}
}
else {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
motionNightTimer = settingPlusMinus(motionNightTimer, LIGHT_TIMER_MIN, LIGHT_TIMER_MAX, sym);
}
settingsMotionSwitchPrint(num, sym);
}
else if (num == 6) {
static int i = 0;
const int numLine3 = 4;
String qwer;
const unsigned int numString[numLine3] = { 3, 6, 12, 15 };
static int clockTime[4] = { 23, 0, 7, 0 };
const int CLOCK_MAX[4] = { 23, 59, 14, 59 };
const int CLOCK_MIN[4] = { 15, 00, 00, 00 };
if (sym == 0x23 || sym == 0x44) {
menuPrint[3] = " : -- : ";
char number = numericKeypad.keyNumber(clockTime[i], CLOCK_MIN[i], CLOCK_MAX[i]);
if (number == 0x23) {
i++;
if (i > numLine3 - 1) {
sym = 0x00;
i = numLine3 - 1;
convertedTime(clockTime);
}
}
else if (number == 0x2a) {
i--;
if (i < 0) {
sym = 0x00;
i = 0;
convertedTime(clockTime);
}
}
for (int j = 0; j < numLine3; j++) {
if (j != i || blinking()) {
if (clockTime[j] > 9){
qwer = String(clockTime[j], DEC);
}
else {
qwer = "0";
qwer += String(clockTime[j], DEC);
}
menuPrint[3].setCharAt(numString[j], qwer[0]);
menuPrint[3].setCharAt(numString[j] + 1, qwer[1]);
}
}
menuPrint[0] = " NIGHT LIGHT TIME ";
menuPrint[1] = " beginning - end ";
menuPrint[2] = " hours:minutes ";
quantArrey = 4;
numberline = 0;
}
else {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
settingsMotionSwitchPrint(num, sym);
}
}
if (sym == 0x2a) {
symMenu = 0x00;
}
}
/*
Настройка соединения WiFi.
*/
void settingPrintWiFi(int numMenu) {
numMenu--;
menuPrint[0] = "SSID WiFi network ";
menuPrint[1] = "Password WiFi ";
if (blinking()) {
menuPrint[numMenu] = " ";
}
quantArrey = 2;
numberline = 0;
}
void settingWiFi(char& symMenu) {
const int NUM_MAX = 2;
const int NUM_MIN = 1;
static bool copyLine = true;
static int num = 1;
static char sym = 0x00;
static String lineChar;
if (num == 1) {
static int i = 0;
const int numLine3 = 20;
char keyChar = 0x20;
const char SYMBOL_MAX = 0x7f;
const char SYMBOL_MIN = 0x20;
static unsigned int length = 0;
if (sym == 0x23 || sym == 0x44) {
if (copyLine) {
lineChar = connectingToWiFi.getNameWiFi();
length = lineChar.length();
copyLine = false;
}
keyChar = lineChar[i];
char number = numericKeypad.keySymbol(keyChar, SYMBOL_MIN, SYMBOL_MAX);
lineChar.setCharAt(i, keyChar);
if (number == 0x44) {
if (i < numLine3 - 1) {
i++;
if (i > length - 1) {
lineChar += String("0");
}
}
}
else if (number == 0x43) {
if (i > 0) {
i--;
}
}
else if (number == 0x2a) {
sym = 0x00;
i = 0;
}
else if (number == 0x23) {
sym = 0x00;
i = 0;
lineChar.trim();
connectingToWiFi.setNameWiFi(lineChar);
}
menuPrint[3] = lineChar;
if (blinking()) {
menuPrint[3].setCharAt(i, 0x20);
}
menuPrint[0] = " SETTING SSID WiFi ";
menuPrint[1] = "A/B prevs/next symb";
menuPrint[2] = "C/D prevs/next char";
quantArrey = 4;
numberline = 0;
}
else {
copyLine = true;
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
settingPrintWiFi(num);
}
}
else if (num == 2) {
static int i = 0;
const int numLine3 = 20;
char keyChar = 0x20;
const char SYMBOL_MAX = 0x7f;
const char SYMBOL_MIN = 0x20;
static unsigned int length = 0;
if (sym == 0x23 || sym == 0x44) {
if (copyLine) {
lineChar = connectingToWiFi.getNamePassword();
length = lineChar.length();
copyLine = false;
}
keyChar = lineChar[i];
char number = numericKeypad.keySymbol(keyChar, SYMBOL_MIN, SYMBOL_MAX);
lineChar.setCharAt(i, keyChar);
if (number == 0x44) {
if (i < numLine3 - 1) {
i++;
if (length == 0) {
lineChar = String("0");
i = 0;
length = 1;
}
if (i > length - 1) {
lineChar += String("0");
}
}
}
else if (number == 0x43) {
if (i > 0) {
i--;
}
}
else if (number == 0x2a) {
sym = 0x00;
i = 0;
}
else if (number == 0x23) {
sym = 0x00;
i = 0;
lineChar.trim();
connectingToWiFi.setNamePassword(lineChar);
}
menuPrint[3] = lineChar;
if (blinking()) {
menuPrint[3].setCharAt(i, 0x20);
}
menuPrint[0] = " SETTING PASSW WiFi ";
menuPrint[1] = "A/B prevs/next symb";
menuPrint[2] = "C/D prevs/next char";
quantArrey = 4;
numberline = 0;
}
else {
copyLine = true;
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
settingPrintWiFi(num);
}
}
if (sym == 0x2a) {
symMenu = 0x00;
}
}
/*
Основное меню.
*/
void settingPrint(int numMenu) {
numMenu--;
menuPrint[0] = "Setting clock ";
menuPrint[1] = "Setting alarm clock";
menuPrint[2] = "Setting motion swit";
menuPrint[3] = "Setting WiFi ";
if (blinking()) {
menuPrint[numMenu] = " ";
}
quantArrey = 4;
numberline = 0;
}
void settings(char& symMenu) {
const int NUM_MAX = 4;
const int NUM_MIN = 1;
static int num = 1;
static char sym = 0x00;
if (num == 1) {
if (sym == 0x23 || sym == 0x44) {
settingClock(sym);
}
else {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
settingPrint(num);
}
}
else if (num == 2) {
if (sym == 0x23 || sym == 0x44) {
settingsAlarms(sym);
}
else {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
settingPrint(num);
}
}
else if (num == 3) {
if (sym == 0x23 || sym == 0x44) {
settingsMotionSwitch(sym);
}
else {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
settingPrint(num);
}
}
else if (num == 4) {
if (sym == 0x23 || sym == 0x44) {
settingWiFi(sym);
}
else {
sym = numericKeypad.keyMenu(num, NUM_MIN, NUM_MAX);
settingPrint(num);
}
}
if (sym == 0x2a) {
symMenu = 0x00;
}
}
/*
Заставка.
*/
void menuPrintSetting() {
static char sym = 0x00;
int number = 0;
if (sym == 0x23 || sym == 0x44) {
settings(sym);
}
else{
sym = numericKeypad.keyMenu(number, 0, 1);
static String realTimeRTC;
String line21;
String line22;
String line31;
String line32;
bool autoMainLight = true;
bool autoNightLight = true;
if (connectingToWiFi.connection()) {
line21 = "WiFi On ";
}
else {
line21 = "WiFi Off ";
}
if (alarmClockOn) {
line22 = " Alarm On ";
}
else {
line22 = " Alarm Off";
}
if (motionMainLightOn) {
line31 = "Main On ";
}
else {
line31 = "Main Off ";
}
if (motionNightLightOn) {
line32 = " Night On ";
}
else {
line32 = " Night Off";
}
menuPrint[2] = String(line21 + line22);
menuPrint[3] = String(line31 + line32);
realTimeRTC = rtc.timeToString();
for (int i = 0; i < 16; i++) {
if (i < 9) {
menuPrint[0].setCharAt(i, realTimeRTC[i + 17]);
}
menuPrint[1].setCharAt(i, realTimeRTC[i]);
}
quantArrey = 4;
numberline = 0;
}
}
/*
Синхронизация времени.
*/
void synchronizationTime() {
if (connectingToWiFi.connection()) {
clockSynchronization.setTimeZone(rtc.getTimeZone());
if (clockSynchronization.synchronization(clockSynchOn)) {
rtc.timeSynchronization(clockSynchronization.getDateTime());
rtc.setTimeZone(clockSynchronization.getTimeZone());
}
}
}
/*
Работа будильника.
*/
void alarm() {
uint8_t week = rtc.timeToDateTime(6);
uint8_t hour = rtc.timeToDateTime(3);
uint8_t minute = rtc.timeToDateTime(4);
if (alarmClock.alarm(week, hour, minute, alarmClockOn)) {
mainLight->switchOn(alarmMainLightOn);
additionalLoad->onTimerSwitch(additionalAlarmTimer, alarmAdditionalLoadOn);
}
}
/*
Работа датчика движения.
*/
void motionSwitch() {
if (motionSensor.sensorWorked(motionSensorOn)) {
uint8_t hourTime = rtc.timeToDateTime(HOUR);
uint8_t minuteTime = rtc.timeToDateTime(MINUTE);
int sensorTime = static_cast<int> (hourTime) * 60 + static_cast<int> (minuteTime);
if (sensorTime >= motionDayTime && sensorTime < motionNightTime) {
mainLight->onTimerSwitch(motionMainTimer, motionMainLightOn);
}
else {
nightLight->onTimerSwitch(motionNightTimer, motionNightLightOn);
}
}
}
/*
Работа выключателей.
*/
void buttonSwitch() {
if (buttom1->clicked() || buttom2->clicked()) {
mainLight->switchOnOff();
}
}
void loop() {
mainLight->offSwitchTimer();
nightLight->offSwitchTimer();
additionalLoad->offSwitchTimer();
synchronizationTime();
alarm();
motionSwitch();
menuPrintSetting();
buttonSwitch();
displayLCD.printMenu(menuPrint, quantArrey, numberline);
}