# Will millis() rollover be a problem in this instance

I just read Gammon's topic on rollover millis() and am glad to see it's not a problem if I use the right formatting. I have one question though. In this particular instance, my idleTime has to be a long and not an int, because I'm waiting 1800000 seconds:

long idleTime = 1800000; //if we've been idle this long, we'll go to sleep if (millis() - wakeTime > idleTime) { //has it been 30 minutes since the ants were fed? digitalWrite(receiverPowerPin, HIGH); //this turns OFF receiver sleep_now(); //if the mower's still in use, it'll wake right back up from the interrupt on the mercury switch //WE WAKE UP HERE, SO RESET/RESTART THINGS: wakeTime = millis(); digitalWrite(receiverPowerPin, LOW); //this turns OFF receiver }

So in the expression:

if (millis() - wakeTime > idleTime) { //has it been 30 minutes since the ants were fed?

Will it matter that idleTime is a LONG, and not an INT? I know in Gammon's topic explaining why rollover isn't a problem it was because the math was done as an int, so it dropped the negative sign/bits.

Why not just use unsigned long? The math only works if you subtract as shown. And anything else you do with the numbers may be confusing if you are only using Long.

Long -is- Int.

http://arduino.cc/en/Reference/long

As polymorph says. Also, if you use numbers instead of idleTime get into the habit of using ex. 1500UL or 60ul * 60ul * 24ul

LarryD: As polymorph says. Also, if you use numbers instead of idleTime get into the habit of using ex. 1500UL or 60ul * 60ul * 24ul

UL? I'll have to google that. Must be

polymorph: Why not just use unsigned long? The math only works if you subtract as shown. And anything else you do with the numbers may be confusing if you are only using Long.

Long -is- Int.

http://arduino.cc/en/Reference/long

I see. Thanks.

polymorph: Long -is- Int.

http://arduino.cc/en/Reference/long

long is not an int on this platform. int is 16 bits and long is 32 bits.

http://arduino.cc/en/Reference/int

``````long idleTime = 1800000; //if we've been idle this long, we'll go to sleep
``````

Your code is OK as written. 1800000 will fit into a long.

I know in Gammon's topic explaining why rollover isn't a problem it was because the math was done as an int, so it dropped the negative sign/bits.

The math was done with an unsigned long. The important word here is unsigned.

The int type is signed.

Thanks again. I'm glad to understand it better.

What level of sleep are you using?

I think that in some of the deeper sleep levels (Power-save?, Power-down?), the timers are stopped so millis() would only count time awake, not clock time.

Oops. I meant that Long is an -integer-, not the same as an int datatype.

``````    digitalWrite(receiverPowerPin, HIGH);  //this turns OFF receiver