Pages: [1]   Go Down
Author Topic: Timed action help  (Read 503 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys,

I'm new to the Arduino scene, is this a correct way to create a long delay or is there a better way?

I need to run this code 10 hours from now so in my void setup() I have delay(36000000); 

is this ok way to do this or is this bad for my arduino?
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 93
Posts: 3968
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That is OK, it will not harm anything. There are other ways. The downside to using delay() is that while delay is doing its thing, nothing else can happen. So if there is nothing else to do, then delay is ok. For another way, see File > Examples > 02.Digital > BlinkWithoutDelay. Also search the forum for "BlinkWithoutDelay" and you'll probably find more discussion on the topic than you can enjoy! smiley-wink
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok perfect, yeah in this case nothing else needs to happen during the delay.

I will check out those links for the future!

thanks
Logged

Durham UK
Offline Offline
Full Member
***
Karma: 1
Posts: 167
aka Craig Turner
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Delay() will work, but you will be wasting a lot of power whilst your device is waiting to do it's task. That may mean a flat battery if battery powered. You could put your Arduino to sleep for much of the waiting time and save power.

See http://arduino.cc/playground/Learning/ArduinoSleepCode

and Nick Gammon's page http://www.gammon.com.au/forum/?id=11497

I managed to get current  down to a few uA in sleep using these techniques.

Cheers


Logged

Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11694
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you need accurate timing the sleep-mode watchdog timer isn't going to be good enough.  But a real-time clock module can give you that and the ability to remember the time across power cycles too.  For instance you could sleep for a minute or so at a time, wake up and check the RTC then either go back to sleep or perform the action.

There's probably something about this at the JeeLabs blog http://jeelabs.org/ (search box at bottom of page!)
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: