Flashing two LEDs but at different time intervals

ashleylad

Member
Hi all, still quite new to PICAXE so go easy. A friend of mine wants a circuit to flash two leds like a mini strobe at different intervals. I am having trouble getting my head around creating a sequence. I suppose I need two programs running together in one, just not sure how to do it.

So for example both leds start at the same time but led 1 flashes every 3 seconds and led 2 flashes every 2 seconds then the sequence repeats.

Any help gratefully welcome. Right off for some ibuprofen for my headache.

cheers

ash

oops forgot to mention I am using a PICAXE 08M device.
 
Last edited:

Goeytex

Senior Member
Try this


Code:
main:

do 
   high 1,2        'both on  
   pause 2000    
   low 1           'LED 1 off after 2 sec   
   pause 1000   'led 2 off after 3 sec   
   low 2
   pause 500    'both off for 500ms
loop               'repeat
 

ashleylad

Member
Thanks mate, but did not pass on full picture sorry.

First led is double flash strobe which I am achieving by this routine:-


High 1
pause 20
low 1
pause 75
high 1
pause 20
low 1
pause 75

Second led is single flash strobe this is how I am doing it:-

High 2
pause 20
low 2


so they need to flash out of sequence with the 3 second delay between the double flash and 2 second between the single.

Confused I know I am............my brain is hurting!


Ash
 

Haku

Senior Member
Repeated flashing of two LEDs in a set pattern, something to do with helicoptors or planes?

If I get this right the sequence you need is:

0 seconds: LED1 double flashes & LED2 single flashes
2 seconds: LED2 single flashes
3 seconds: LED1 double flashes
4 seconds: LED2 single flashes
6 seconds: go to 0 seconds

If so then this should do the trick:
Code:
#picaxe 08m

'dual LED flashing
'LED1 double flashes on a 3 second loop
'LED2 single flashes on a 2 second loop

output 1,2

do

 high 1:high 2:pause 20
 low  1:low  2:pause 75
 high 1:pause 20
 low  1

 pause 1885 ' 2 seconds minus the pause time for the flashing 
 
 high 2:pause 20
 low  2

 pause 980 ' 1 second minus the pause time for the flashing

 high 1:pause 20
 low  1:pause 75
 high 1:pause 20
 low 1

 pause 885 ' 1 second minus the pause time for the flashing
 
 high 2:pause 20
 low  2

 pause 1980 ' 2 seconds minus the pause time for the flashing

loop
 
Last edited:

ashleylad

Member
Haku, you make it look so easy. Thanks for taking the time to post a solution. I will implement the code into the circuit later.

cheers

Ash
 

boriz

Senior Member
Or this...

Code:
do
	pause 20
	inc w0
	b2=w0//99
	b3=w0//149
	if b2=0 then high 1 else low 1:endif
	if b3=0 then high 2 else low 2:endif
loop
Because the only pause in the loop is for 20mS, this is the basic time multiple. 100*20mS = two seconds. 150*20mS = three seconds. Using the Modulus Divide provides a convenient method of counting specific intervals. 99 and 149 are used because zero counts as one 20mS interval. B2 will count from 0 to 99 and loop in two seconds, b3 from 0 to 149 and loop in three seconds. Each will spend exactly 20mS on zero during its loop.

I like this method because the two LEDs flash as if according to their own rhythm. They are not synchronised with each other. Using a slightly different count, say 97 instead of 99 will further improve this non-synchronicity, making it look just a little more realistic as the flashing drifts slowly in and out of phase.

Note. When w0 gets to 65535, there will be a slight glitch in the timing as w0 loops back to zero and the sequence resets. With the base time multiple of 20mS, this will happen every 28 minutes or so. You’ll be hard pushed to ever spot it.
 
Top