This topic is a little summary of the research I did this morning on the unsigned long millis(). If it doesn't add any existing knowledge, then let the post be for reference purposes only.
Millis() function itself
Unsigned long 32bit variable. Meaning 2^32-1 milliseconds range (no negative numbers possible). This equates to: (2^32-1) / 1000ms / 60sec / 60min / 24hr = 49.71 days. Or 49 days and 17 hours. Millis() is derived from timer0_millis
, and overflows result in the number returning to zero (and continuing counting from zero). Overflows do not crash the arduino, Millis() overflows do not crash your code, and the timer will not stop counting. However, if you want events to happen fewer than once every 50 days, you should use RTC and the time library.
Difficulties arising from Millis() overflow
Take a look at Gammon's explanation of the millis() issue, and what is often done wrong that causes errors. In brief, setting your stop-time ahead of the current time, and creating an if-statement that checks when the current time exceeds the "stop-time" variable will create issues near overflow. However, Using the difference between current time and stop time, and comparing that to a set interval will never create issues. (see link for code examples).
I've edited to text below to accommodate for future reference:
Is it possible to reset Millis()? Yes, though not recommended:
According to the official wiring.c source code (see here: Wire.c), Millis() is derived from timer0_millis. For this reason, timer0_millis can basically be seen as just another unsigned long, in fact it is. Thus, it can be manipulated at will by the programmer. Please realize that the code below is a "hack" that shouldn't be used unless you know and you've tested its effects on your millis()-dependent libraries. It is better to use an external RTC with the Time library for accurate time management.
Before void setup(), place:
extern volatile unsigned long timer0_millis;
Whenever you want to reset millis():
noInterrupts ();
timer0_millis = 0;
interrupts ();
Thanks for reading, hope it adds some new info to this forum
Many thanks to the forum members below, especially Gammon, for careful explanation and elaboration of the issues at hand!