I'm writing a program that sends signals to 4 small pumps, turning them on and off in a specified sequence that repeats after an interval. Every time a 'time where something needs to happen' is reached it is sends the signal and increases that time by the interval so that the process can repeat.
I am worried about millis() rolling over while I am in the sequence, and causing the sequence to restart. What I wanted to do is check how many times I can run the sequence in the 50 days, and then force millis to roll over so that the timing doesn't get interrupted.
Is it possible to do this? Or could someone suggest another way?
Thanks in advance
Or could someone suggest another way?
Write your own "millis" wrapper (or macro) that offsets the real "millis" by something approaching the 232 limit, and returns that value.
Mate if you don't mind could you let me know how I would implement that. Cheers
C provides a handy operator called '+'.
Make a function called "my_millis" returning an unsigned long, and call it instead of "millis".
When you're convinced the roll-over doesn't cause you problems, change the offset to zero.
Sweet thanks man, nice and simple!
For the rest of us still wondering...
It the time scale in question is <60 seconds one can even use ints.
unsigned long msOffset;
unsigned int myMillis(){
return millis()-msOffset;
}
void resetMyMillis() {
msOffset = millis();
}