Need programming help in creating a delay

Hi,

I need to stop the loop function for 10 hours, if a condition goes true, and after 10 hours, it should work as normal, will this line of code

delay(10*60*60*1000)

work, or should I try millis() function, which one would be good, kindly suggest

Hello Siddique

I don´t know your project requirements.

If you want the sketch to freeze, ie do nothing, for 10 hours then delay() is a suitable way to do it

If you want the sketch to be able to do something during the 10 hours, such as reading an input to bring the wait to an end, then millis() is the way to go

You have not said, but I suspect that your

delay(10*60*60*1000);

is not working because the calculation will be done using ints and the result is too big for an int to hold. If that is your problem try

delay(10*60*60*1000UL);   //force calculation to use unsigned long

As mentioned, the only real way to handle this is with millis()

Just test the interval every time around loop(), and if your external condition is also true, trigger the event.

For testing, you can reduce the timed interval to a useful duration, like 10 seconds etc, then put it back to the long period when you’re sure it works as needed.

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