Go Down

Topic: Programming timer (Read 194 times) previous topic - next topic

teodoro

Heys guys, i'm new here so i'm sorry if this is not the right way to start a topic. Let me now about that.

My doubt here is the folowwing:
I'm using an Arduino Uno and trying to program a timer for it. The problem is, i don't have any other plug-in arduino hardwares, only this Uno board and i want to program a timer with many hours of intervals, like 18 hours with a led turned on and many other hours turned off.
I've red about the function delay() but i don't know what is the maximum value of milisseconds it supports, also some people said it's not a good function to be used for a long time because can suddenly reset and not work anymore until i get reprogammed.

I don't need to do anything else but to turn on and off a light, so the function delay would be perfect for it, but i have this doubts above.

Thanks!

dustin02rsx

Admittedly, I don't know how long you can use the delay function reliably. But you can use millis(); for approximately 50 days and have the advantage of still being able to complete other tasks while timing the event.

avr_fred

#2
Aug 11, 2017, 07:57 pm Last Edit: Aug 11, 2017, 07:59 pm by avr_fred
delay() can called with a value as large as 4,294,967,295 (unsigned long).

But you really, really should not use that ability as your program can do nothing until the delay() times out.

Learn how to do two things at once, this involves learning how to do time calculations correctly with the internal time value that the Arduino maintains. This value is accessed with the millis(); function.

Examine the "Blink without delay" demo program in the IDE examples section and

http://www.gammon.com.au/millis

edit: when you want to know what parameters a built-in function will accept, look it up in the reference section of the IDE. The same documentation is also available online.

https://www.arduino.cc/en/Reference/Delay

DrAzzy

Also - be aware that the internal clock on the Arduino is only accurate to within a percent or two, so depending on how much accuracy you need in your delays, you may need an external RTC module.
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

teodoro

delay() can called with a value as large as 4,294,967,295 (unsigned long).

But you really, really should not use that ability as your program can do nothing until the delay() times out.

Learn how to do two things at once, this involves learning how to do time calculations correctly with the internal time value that the Arduino maintains. This value is accessed with the millis(); function.

Examine the "Blink without delay" demo program in the IDE examples section and

http://www.gammon.com.au/millis

edit: when you want to know what parameters a built-in function will accept, look it up in the reference section of the IDE. The same documentation is also available online.

https://www.arduino.cc/en/Reference/Delay

Thanks a lot! Very useful. I'm gonna use milis() now.

Go Up