having problems with delay function.

this is just a example of whats going on here the first delay never stops it works when i change it to 60000ms but not as shown below but the 30 sec delay works just fine. any input on why this is would be great.

int ledpin = 13;
void setup(){
pinMode(ledpin, OUTPUT);}
void loop(){
digitalWrite(ledpin, HIGH);
delay (1000 * 60);
digitalWrite(ledpin, LOW);
delay (1000 * 30);

Perhaps you are seeing an integer overflow. Does it work better if you do:

    delay(1000UL * 60UL);


yes works great if i may what does the UL stand for or do so to say. i a little new to all this just trying to figure it out the best i can.

Normally, in C, integer constants are treated as 16-bit integers, the size you get when you declare an int. Unfortunately for the case at hand, a 16-bit integer can only store numbers from -32768 to +32767. When you multiply 60 times 1000, it overflows, and only the lowest 16 bits are kept.

Appending UL to a constant makes it into an unsigned long, which is 32 bits on Arduino, so the arithmetic works, and the result happily is what delay() expects for an argument.

You can also say 123L to get a long as opposed to 123UL to get an unsigned long.


ok that makes alot of sense now thank you.

Normally, in C, integer constants are treated as 16-bit integers

You should be careful to make the distinction between "integer" and "int". Integer constants are treated as whatever width they are declared as (integer types include "char", "int", "long" etc).

However, in C the width (number of bits) in an "int" depends on the platform, so on an Uno, an "int" is sixteen bits, but an "int" on a Due is thirty-two bits.