
Generally far more useful to think of millis() as returning a Interpretation, however, breaks down as soon as millis overflows. Time elapsed from the start of the program until now. The return value of millis() could be interpreted as a duration: the Important, because it is the simplest way to entirely avoid the rollover For example, if I say “ I willīe back in five minutes”, then “ five minutes” is the estimatedĭuration of my absence, whereas “ in five minutes” is the instant The distinction between these concepts is notĪlways very sharp in everyday language. the distance in time between the instants that define the start and A duration is the length of a time interval,

Two different concepts: instants and durations. When dealing with time, we have to make the distinction between at least Note on micros(): Everything said here about millis() appliesĮqually to micros(), except for the fact that micros() rolls overĮvery 71.6 minutes, and the setMillis() function provided belowĭoes not affect micros(). Only involve comparing durations, you should be fine. It is based on the simpleĭistinction between instants and durations. (hopefully simpler) way of thinking about it. Go through the computational details, I offer here an alternative “wrap around” when reaching a certain value – the modulus – so thatġ − modulus is not a negative number but 1 (think of aġ2 hour clock where the modulus is 12: here 1 − 12 = 1). What's important to know is that in modular arithmetics the numbers You can see the math in action in Nick Gammon's Mathematically inclined, some familiarity with this concept is very Rollover problem is to think of the unsigned long number returned by The correct way to manage (or rather, avoid having to manage) the

Then, and even if the program is meant to runįor years at a time, the millis rollover should not be a concern. Programs only have to manage events that span relatively shortĭurations, like debouncing a button for 50 ms, or turning a heater

Measures, chances are you are doing something wrong. If you try to detect the rollover in order to implement corrective
#ARDUINO MILLIS VS DELAY CODE#
Your example code from the tutorial is fine. Short answer: do not try to “handle” the millis rollover, write
