Pages: [1]   Go Down
Author Topic: Temporization without delay  (Read 419 times)
0 Members and 1 Guest are viewing this topic.
Finland
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody,

First of all, Happy New Year to everybody!

I'm trying to find out how to create a temporization without the delay() function.
If a digital input is set to HIGH, I would like one output stays a certain time (40 seconds in my case) to the HIGH level before going back to LOW, and only one time.
Like I'm running several loops at the same time, if I use the delay() function in one loop, it will also stop all the other loops what I don't want. I tried to use the Millis() function from the Blinking Led example but the output doesn't stop to be HIGH and LOW with a period of 1.2 min.
How can I do?

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46107
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I tried to use the Millis() function from the Blinking Led example but the output doesn't stop to be HIGH and LOW with a period of 1.2 min.
How can I do?
Using millis() to record when the pin was set HIGH, and then setting it LOW at some later time is the correct approach.

If it failed to work, it is because you didn't turn the pin off at the right time.

Post the code that you are using, and we'll help you figure out what the problem is.

Alternatively, the hard work has been done for you.
http://www.arduino.cc/playground/Code/TimedAction
Logged

Pages: [1]   Go Up
Jump to: