Add a timer function , without stopping  a loop?

I am making an Automation Controller at the moment and i want to add a shutdown timer for one of the outputs.

I have outputs being controlled via An webpage ect controlled in a loop.

I want to have a timer , that once set will turn a given output off in aprox 30 mins ie a (sleep timer) . But is posible for the timer to run without making the current function having to pause for the timer to finish ?

IF this is not possible i was looking at just making a simple timing external circuit 555 timer ect and it just sets an input high once a capacitor has charged. But this is not ideal really .

So any ideas , Any help would be great

thanks for looking

luke

Something like the event fuse library?
http://www.arduino.cc/playground/Code/EventFuse

otherwise, no, you don't have to make a function wait.
Think how you would do it yourself.
Look at the clock, note the time.
Label:
Go off do something else.
Look at the clock.
Is time now > noted time plus 30 minutes? No - goto Label.
Yes: turn off output.
and so on.

I'll throw in two more alternative libraries:

http://www.arduino.cc/playground/Code/TimedAction
A library that will call a function at a set frequency. Without blocking the rest of the program.

http://www.arduino.cc/playground/Code/Scheduler
This lets you schedule a function call in some amount of microseconds.

Say you have an on and an off function. Then you can call:

on();
scheduler.schedule(off, 30*60*1000);

Good luck! :slight_smile:

BTW, if you use the Timed Action lib (which is very nice) you will have to modify it to get 30 min. intervals.
As is, it can only support an interval of 65535 mS (~65 sec.).

You can get around this by incrementing a counter in the called function until it reaches say 30 and then reset it and do your stuff.

Another way around it is to change TimedAction.cpp & .h to use an unsigned long rather than an unsigned int you can have the interval you need. This works for me, and saves you a global and a counter.