Go Down

Topic: Reset millis (Read 3491 times) previous topic - next topic

David Pankhurst


I have never used or even seen the modulo (%) used anywhere before, but it's an ingenious way of achieving this result, and one which I would have never considered.
Assuming that the counter is started at midnight, (to gather a full day's data), what would happen if after 49 days and millis overflows and returns back to zero, say at midday when myMilliseconds = 43200000 ?
Will myMilliseconds continue on to  43200001, 2, 3 ect.
Or, will it return back to zero (and start the 24 hour counter from midday instead of midnight, throwing the 24hr period out of sync).


Because 4294967296 % 86400000 = 61367296 (4294967296 is the equivalent of the rollover 0)), then the next day at midnight you're not be at zero, but 61,367,296. You'd have to take that into account from now on, perhaps by subtracting this value before taking the modulo. However, unless you really plan to run something for 50 days, this likely won't be an issue.


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy