adding up millis

bperrybap:

CrossRoads:
If your math is all done in the form of

elapsedTime = (timeNow - timeEarlier); // add elaspedTime to add rideTime summary
where timeNow is the stopped time, and timeEarlier is the time you started

and all time related variable are unsigned long,
then there will not be a rollover problem.

If timeNow and timeEarlier are values form millis(),
then that will only work if the millis() timer is guaranteed to never rollover
between TimerEarlier and timeNow.

To ensure no rollover during the elapsed time requires zeroing out the millis() timer value.
(which is easy)
And if the millis() timer value has to be zeroed to make it work, why not then just
zero at "timeEarlier" when the elapsed time starts, and then the elapsed time
is merely mills() when you get to timeNow.
This avoids the calculation altogether.
It then simply becomes a matter of when to zero out millis().

--- bill

Incorrect, subtracting two unsigned numbers will result in the difference between the two numbers, including wrap-around. Try it for yourself.

The only caveat is that you can only detect an elapsed time that is less than the maximum amount that can be stored in the n-bits you are working with.