AlarmTime += 5; // Adds 5 seconds to alarm time
AlarmTime = AlarmTime % 60; // checks for roll over 60 seconds and corrects
rtc.setAlarmSeconds(AlarmTime); // Wakes at next alarm time, i.e. every 5 secs
Say, you have a watch showing MIN:SEC (Minute:Second). The SEC field is advanced by 5-sec, and it will advance this way: 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55.; after next 5-sec, the display will show the time as: 01:00.How to implement this line of thought?
1. Let us have a SEC Counter named : AlarmTime with initial content of 00.
2. Wait for 5-sec and then add this 5-sec with AlarmTime: AlarmTime = AlarmTime+5 (AlarmTime +=5).
.....................................
X1. After repeated advancement by 5-sec quanta, the AlarmTime will contain 55+05 (60). This indicates that 1-MIN has elapsed. The MIN-field will hold 01 and the SEC-field will hold 00. Here, we have two components - 01 called quotient (Q) and 00 called remainder (R); these two factors have to be derived from 60 (the content of AlarmTime). The procedures could be:
(a) Divide 60(AlarmTime content) by 60 (as 60 sec makes a minute) and keep the remainder (00) without disturbing the original content of AlarmTime. This is automatically done when we execute the instruction: R = AlarmTime % 60;. Here, % is called the modulus operator and R will hold 00.
(b) Divide 60(AlarmTime content) by 60 (as 60 sec makes a minute) and keep the quotient (01 = the overflow). This is automatically done when we execute the instruction: Q = AlarmTime / 60;. Here, / is called the division operator and Q will hold 01.