Is there a trick to set a start time and a stop time within a 24 hour period?
I don’t want to use a timer it must use the RTC incase the system resets.
For instance I want to start at 20:00 hours and stop at 05:00 hours, that means going past midnight.
I’m using this to get the seconds and process it from there, but I’ve got a bit of brain freeze and there has to be a simple solution.
void autoLOCK()
{
int hour_from, minute_from = 0;
int seconds_from = 0 ;
int hour_to, minute_to = 0;
int seconds_to = 0;
if (sscanf(lockFrom, "%d:%d", &hour_from, &minute_from) >= 2)
{
seconds_from = (hour_from * 3600 + minute_from * 60);
}
if (sscanf(lockTo, "%d:%d", &hour_to, &minute_to) >= 2)
{
seconds_to = (hour_to * 3600 + minute_to * 60);
}
Serial.printf("\n\nSeconds from: %d\n", seconds_from);
Serial.printf("Seconds to: %d\n", seconds_to);
Serial.printf("Seconds now: %d\n", seconds_now);
lockStatus = 0;
if (seconds_now >= seconds_from) {
lockStatus = 1;
Serial.printf("Lock Status 1: %d\n", lockStatus);
}
if (seconds_from > seconds_to) {
lockStatus = 1;
Serial.printf("Lock Status 2: %d\n", lockStatus);
}
if (seconds_now >= seconds_to && seconds_from >= seconds_to) {
lockStatus = 0;
Serial.printf("Lock Status 3: %d\n", lockStatus);
}
Serial.printf("Lock Status: %d\n\n", lockStatus);
}
Any help would be appreciated.