Calculations using the variables of the current time.

I am trying to do the following:

x =current hour *60 + current min;

How can I use the current time as a variable in this context? I want to get the time from a RTC that has the time already stored.

Something like this:

x = (hour(now) * 60) + (minute(now));

depending on the format in which your RTC outputs the time.

I really hope that the RTC has a way to provide hour(now) and minute(now) in a way that won't be a problem when the hour changes (and the minute goes from 59 to 0).

Alternatively, I hope that the calculation gets repeated until hour(now) and minute(now) don't change from before the calculation until after the calculation.

vaj4088: I really hope that the RTC has a way to provide hour(now) and minute(now) in a way that won't be a problem when the hour changes (and the minute goes from 59 to 0).

Alternatively, I hope that the calculation gets repeated until hour(now) and minute(now) don't change from before the calculation until after the calculation.

"When reading or writing the time and date registers, secondary (user) buffers are used to prevent errors when the internal registers update. When reading the time and date registers, the user buffers are synchronized to the internal registers on any START and when the register pointer rolls over to zero. The time information is read from these secondary registers, while the clock continues to run. This eliminates the need to reread the registers in case the main registers update during a read." - DS3231 datasheet.

This means that the values remain consistent as long as they are all read with a single I2C bus transfer. Which all the good libraries use.