i am trying to understand these lines of code but not able to
can someone please explain me what it does?
int MinToday = (myRTC.hours * 60) + myRTC.minutes;
int MinEprON = (EEPROM.read(adrON) * 60) + EEPROM.read(adrON + 1);
int MinEprOF = (EEPROM.read(adrOF) * 60) + EEPROM.read(adrOF + 1);
‘Min’ are minutes, MinToday are minutes of the day calculated from realtime clock data. every hour has 60 minutes plus current minutes of the day adds to minutes from midnight.
MinEprON and MinEprOF are time stored in eeprom memory on addresses adrON and adrOF in form of hours and minutes. minutes in address adrON + 1 and adrOF + 1
It is converting 3 time values that are stored as hours and minutes into a minutes. For example 3h:35m gets converted to 215. I suspect the purpose of that is to make comparisons easier.
In the EEPROM the hour value is stored at the byte at the address adrON and the minute value is stored in the next byte, hence adrON + 1
THANKS A LOT ROBIN,
your explanation was good, i understood easly.
I GOT TO KNOW WHY WE ARE DOING THAT.
THANK YOU JURAJ.
That is why descriptive names are more important than saving characters:
int MinutesSinceMidnight = (myRTC.hours * MINUTES_PER_HOUR) + myRTC.minutes;
int OnTimeMinutesSinceMidnight =
(EEPROM.read(OnTimeHourEEPROMAddress) * MINUTES_PER_HOUR) +
int OffTimeMinutesSinceMidnight =
(EEPROM.read(OffTimeHourEEPROMAddress) * MINUTES_PER_HOUR) +
Remember: Variable names are not stored in memory so they don’t add to the memory footprint of your sketch. They can be as long as necessary to be readable and understandable.