Set millis() after coming out of sleep

Hi there,

I would like to know if it is possible to update/write to millis()?

psuedo code

var millis_now = millis(); //say its 1234mS
//millis_now is still 1234.
//millis() is still 1234.
millis() = millis() += (50*1000)?

No that is not possible.
If you want to do something similar you need an intermediate variable.

yeah I thought that would be the case, its a real shame, as so much code relies on millis() and then if you sleep, everything breaks.

I think that this would be a great addition to 1.5.0…
after coming out of sleep millis() is updated by the time that the unit was asleep. - albeit with the disclaimer that it is not that accurate. (+/- 1000mS) you would have to use the to determine how long it slept for.

I think this highlights that this is a thing you should not be using millis() for.

millis() gives you a count of milliseconds of program run time since start, which is useful for short-ish timers and delays. Measuring very long times or times that exist in reference to the real world (like figuring out what time it is after a sleep) is what the Time library is for.

You don’t really want to be tempting the system with a millis() overflow, although it would be a nice bug-test feature.

1 Like