Pages: [1]   Go Down
Author Topic: Periodic LED and on demand  (Read 625 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

i'm semi-new to arduino still and what I want to do seems pretty simple but I have not been able to do it yet.

All I want to do is:

have one LED (and another pin) go to HIGH for .5sec, LOW for .5sec (or whatever times I choose)

and

have another LED come on when a button is depressed.

The problem i'm having is that the periodic LED takes 1 or two seconds to loop through and I cannot trigger the other LED while waiting for the first one to cycle through.

I want to do this wirelessly but that shouldnt be a problem.

thanks in advance
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 54
Posts: 1857
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The general solution is not to use the delay function.  Look at the blink without delay example: http://arduino.cc/en/Tutorial/BlinkWithoutDelay
Logged

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

Thanks, i'll give it a try.
Logged

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Another approach is as follows...

Work things so that your "loop" executes 100 times per second, or so.

And have your "on for a bit" LED go on for 50 passes through the loop, if you want it on for 0.5 second. (You can do this with a variable you might call bCountDownToOff... set it to 50 when you turn the LED on, decrement it (subtract 1) each time you go through "loop", and turn LED off when bCountDownToOff reaches zero.
Logged

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

Thanks for the help guys.  I was able to accomplish my goal using the "blink without delay example".  If I have spare time I may try the countdown method but I'm wondering if the speed that the processor is able to get through the loop changes based on the task that it is working on.  I will be recording the 5v output signal on two different data loggers and using it sync the two units, so it's pretty important that the signal is consistent.  A few millisecs off here or there is ok but not much more.

Logged

Pages: [1]   Go Up
Jump to: