The subtraction method of calculating elapsed time means you don't need to care if it overflows or not.
Nick, bravo to you and Coding Badly. I made one last test, and now I can get on with the rest of
my life. I took Morris' original example, start of this thread, and tried both sets of lines below,
along with starting the clock near the wraparound point.
extern unsigned long timer0_millis;
timer0_millis = 4294967295UL - 5000UL;
- original: this crashes on wrap, and it crashes horribly if change >= to > in the test.
blinkTime = millis() + 250; /* Schedule next state change */
if (millis() >= blinkTime) blink(); /* If it's time to change state, do it */
- subtraction method - this flows:
blinkTime = millis(); /* Schedule next state change */
if( (millis() - blinkTime) >= 250) blink(); /* If it's time to change state, do it */