Help with "until" loop

Of course.

Gack! Well today your lucky day.

I bet it isn't ~54 seconds, but precisely 54.464 seconds.

Please make a tiny change to your simulation, and to your real code if it has the same problem I will describe.

const unsigned long flushForTime = 20000;    // flush on duration in milliseconds
const unsigned long pauseForTime = 120000;   // wait between flushes

Any variables that are involved with timing using the various millis() mechanisms should be unsigned long unless you really know what you are doing.

@alto777 plays it fast and loose and is sloppy.

Since the times I used for the durations were unsigned int, a type with but 16 bits, when you ask for 120000 it doesn't fit in that variable, and the part that does fit is 120000 modulo 65536, or just the bottom 16 bits of 120000. 54,464. About 54 seconds.

Had I increased those times, or taken into account the known fact that you were going to, I would probably have noticed and made at least the 120000 an unsigned long.

I can't test it: I am with two feet out the door to get to the Eclipse on time (airport, actually!), but I can practically guarantee this will fix you up.

Appy polly loggies for all the minutes it took you testing that, I know life is short.

I will flog myself with a damp trout as required by the internet to atone. :expressionless:

And I may just start taking the good advice - just use unsigned long variables for timing, even when you know you don't have to. It's a cheap price to pay.

a7

1 Like