Function to turn on output for given time.

I'm pretty new to C++, and I am trying to get my head around functions.

I know about the blink without delay, and using millis() to do timing while doing other things. The disadvantage of this is that I have to keep checking when the required time has passed.

It should be possible to write a function, say ledOn(500), that would turn on an led for 500mS, and then I just forget about it. I'm thinking interrupts come into it somewhere, but I just can't quite figure it out. Any help would be greatly appreciated.

Regards Bob.

BobEdge: I'm pretty new to C++, and I am trying to get my head around functions.

I know about the blink without delay, and using millis() to do timing while doing other things. The disadvantage of this is that I have to keep checking when the required time has passed.

It should be possible to write a function, say ledOn(500), that would turn on an led for 500mS, and then I just forget about it. I'm thinking interrupts come into it somewhere, but I just can't quite figure it out. Any help would be greatly appreciated.

Regards Bob.

Because there are no native Software Timers on your arduino, you have to keep polling millis() to see if the 500milliseconds have passed.

You would like to attach a callback to a timer... when you toggle the Led on timer runs and then expires. At that moment timer runs a function to turn the led off (callback).

You could look to use a library that uses polling like this one here.

I'm sure that there may be interrupt based timer/callback libraries out there, but I'm not familiar with any.