My two hour delay code only delays seven minutes

Simple code with delay 2 hours

const unsigned long SECOND = 1000;
const unsigned long HOUR = 3600*SECOND;
const unsigned int minuto = SECOND*60;
const unsigned int hora = minuto*60;
horas = 2UL * HOUR;
for(unsigned long h=horas;h>0;h-=1000)
   delay(1000);

delay(2UL*HOUR); Not working, delay only 7 minutes

[sterrretje]code tags fixed

Please don't hijack threads @lercio. I have split your post out to its own topic.

Hijacking is against the Arduino forum rules. The reason is that it may sidetrack the discussion, even preventing the creator of the topic from getting the assistance they need. It also reduces your own chances of getting assistance.

This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

1 Like

Did you mean to put * (multiply) in
const unsigned long HOUR = 3600SECOND;
const unsigned int minuto = SECOND
60;

?

Please use code tags to make your code readable.

Value truncated to signed 16 bit.

1 Like

It appears the code is working as written, but I cannot properly read it to be sure.

The code as you have posted it

const unsigned long SECOND = 1000;
//const unsigned long HOUR = 3600 * SECOND; // NOT 3600SECOND
//const unsigned int minuto = SECOND * 60; // NOT SECOND60
const unsigned long HOUR = 3600SECOND; 
const unsigned int minuto = SECOND60; /
const unsigned int hora = minuto * 60;
unsigned long horas = 2UL * HOUR;

does not even compile because

3600SECOND; 

and

SECOND60

are not defined.
So there is a chance that the actual compilation aborted and not uploaded to the arduino
but instead
a former version of your code is running

If this is corrected like in this code
shown in the wokwi-simulation
it works as expected

best regards Stefan

... code tags are not used!

See the raw quoted code while editing, in contrast to the preview.

@lercio print the values to the Serial Monitor to see which calculations went wrong.

Not sure what you want to say with that
as a screenshot-pixel-picture

then clicked on
image

quotation is shown this way again as a screenshot pixel-picture
image

As you can see the editable quoting is the same
the preview looks like this
again as pixel-picture

If I quote it the multiply-signs are not there
image

An attempt was made by OP to use code tags hence I've fixed them.

By the way, the italics was the dead give-away :wink:

1 Like

@lercio

<code> and </code> are not the way to use code tags; either use
[code]
your code here
[/code]
or
```
your code here
```

if I type

unsigned long deltaT = 10006032; // 32 minutes in ms

it feels wrong but If I add the code tags

unsigned long deltaT = 1000*60*32; // 32 minutes in ms

suddenly the mystery is solved

that's why we insist on using code tags. a star introduce the italic text mode otherwise, a double star the bold text mode (we also used to have issues with previous tags like [i] or [x] that were interpreted to format the text)

Back to the original question, does anyone see the calculation overflow (hora) in the post? And the redefined variable (horas)? Is the OP still with us?

@DrDiettrich flagged it

Leave it at that, then, since the OP hasn't seen fit to return to the thread.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.