I don't wish to "hijack" this thread, but since it was brought-up in a reply, and I have the question...
Does anyone have a tested function or methodology to work with the millis() - total elapsed time since reset - as it rolls-over the max value (every 50 days or so is what the Reference material says)?
Specifically, I have one "test" that I need to conduct to see if something happens WEEKLY, so it's very possible, if the unit is running a decent amount of time, that I would record a value close to ULONG_MAX, then during the following days, the value would be significantly less; messing-up my delta-calculation.
I'm assuming others have already devised a method or strawman to get-around this limitation and was just looking to "not reinvent the wheel".
Make sure your calculations all use unsigned long variables (32bit, 0 to FFFFFFFF)
and the math is always currentmilis - previous millis.
Then even at rollover, if currentmillis = 0x00001000, and older (previous) is 0xFFFFFFF8 for instance, a correct result is returned:
0x00001000 - 0xFFFFFFF8 = 0x00001008
CrossRoads:
Make sure your calculations all use unsigned long variables (32bit, 0 to FFFFFFFF)
and the math is always currentmilis - previous millis.
Then even at rollover, if currentmillis = 0x00001000, and older (previous) is 0xFFFFFFF8 for instance, a correct result is returned:
0x00001000 - 0xFFFFFFF8 = 0x00001008
Nominated for a sticky topic!
Has there even been any thought given to a FAQ forum section that could be posted to perhaps only by moderators after some sort of consensus process? Or maybe it'd be better as a section in the Playground?
CrossRoads:
Probably Jack - getting folks to read it before asking is the tricky bit.
Often folks don't even know what it is they should be looking for.
It would at least make it easier for the people replying to find the link they need to point at
You haven't seen the blink without delay rewrite thread, went on for many pages. I suppose it ended up with a nicer page when all done, but took quite a bit of discussion to get there.
CrossRoads:
Probably Jack - getting folks to read it before asking is the tricky bit.
Often folks don't even know what it is they should be looking for.
It would at least make it easier for the people replying to find the link they need to point at
True, and true!
A central resource page on a given topic would also benefit from various folks reviewing it, and so hopefully be clearer, more complete, etc. Often I'll dash off a reply and maybe it's not as good as it could have been had I engaged the brain a bit more