how can I pause a program several seconds?

How can I put a pause of several (random 10-40)) seconds in a program, before it loops again, since "delay" seems only good for many millisecond delays??

From the reference:

"ms: the number of milliseconds to pause (unsigned long) "

Also from the reference"

"Long variables are extended size variables for number storage, and store 32 bits (4 bytes), from -2,147,483,648 to 2,147,483,647. "

I think that would hold a delay value of over 24 DAYS :wink:

Lefty

Thanks Lefty - but I am hopelessly new at programming this stuff and I don't understand your answer

Can I simply do
delay (50000):
to get a 50 second delay?

  • or do I need to use a "millis ()" instruction - and how do I do that, for example to get a 50 second delay?

I'm really simply looking for a random pause of from 30 to 50 seconds before the look repeats.

Thanks

Thanks

  • while I do get random pauses of a few seconds, when I try to get pauses of several seconds as programed below

pause = random (20000,50000);
delay (pause);

nothing happens!

what's wrong?? There are caveats in the reference for delay.

Yes, "Can I simply do delay (50000): to get a 50 second delay?" should work fine.

"pause = random (20000,50000);
delay (pause);"

Did you define pause as a unsigned long variable?

Lefty

ouch - no I had it assigned as int - now it works as an "unsigned long" as you suggest. - but why the difference?

Many Thanks for the help

but why the difference?

On an Arduino, an "int" is 16 bits, and stores a signed range from -32768 to +32767.
An 2unsigned long2 is 32 bits and stores the range 0 .. 232-1, or a shade over 4 billion (4x109)

Thanks Groove