Programming help

Happy Christmas to you all.

Is there a smarter or easier, way to program the following:

I want to have a slow flashing LED but the input needs to provide a fast response prefferably without using interrupt.

The only way I can do this is to break the pause time into multiple smaller pauses, each with an if statement

so "Pause 500" becomes five, pause 100, with an if statement between each to exit if the input is operated.


Do while input_trigger = 0 ; waiting to be operated

; all these statements give fast response and a slow flash of the led
; equivelent to 500 on 500 off
high led
pause 100 ; slow flashing led
if input_trigger = 1 then goto main
pause 100
if input_trigger = 1 then goto main
pause 100 ; slow flashing led
if input_trigger = 1 then goto main
pause 100


if input_trigger = 1 then goto main
pause 100
if input_trigger = 1 then goto main

low led
pause 100 ; slow flashing led
if input_trigger = 1 then goto main
pause 100
if input_trigger = 1 then goto main
pause 100 ; slow flashing led
if input_trigger = 1 then goto main
pause 100
if input_trigger = 1 then goto main
pause 100

loop
 
Last edited:

Hemi345

Senior Member
In a loop, increment a counter variable and then check that counter against a constant variable with an 'if' statement. Tune your constant value till you get the delay to your liking.
 

Hemi345

Senior Member
Code:
Symbol myCtr = b0 'counter
Symbol myDelay = 100 'constant
Symbol blinkinLed = C.3

Do
    Inc myCtr
    If myCtr >= myDelay then
       myCtr = 0
       Toggle blinkinLed
    End if
Loop
May need to use a word variable for the counter if blinking is still to fast (so you can use a constant > 255)
 
Excellent!

I have tried it in my main program and all is good.

Just what I need, neat, easy to adjust and short.

I can change it for my uses.

Toggle is a new command to me.

Thank you.
 

PhilHornby

Senior Member
Is there a smarter or easier, way to program the following:

I want to have a slow flashing LED but the input needs to provide a fast response prefferably without using interrupt.
As an alternative, assuming an "M2" Picaxe, you could take advantage of the 'multi-tasking' support.
Rich (BB code):
#picaxe 08m2
#no_Data
#no_end

symbol LEDPin = C.2           
symbol InputTrigger = PinC.3

symbol FlashSpeed = W0

symbol Slow = 1000
symbol Fast = 250

Start0:
;
; Main task
;
do
      if InputTrigger = 1 then
            ;
            ; Trigger Input high - set flashing speed high as indication
            ;
            FlashSpeed = Fast 
      else
            ;
            ; else - set it to slow instead
            ;
            FlashSpeed = Slow 
      endif
loop

Start1:
;
; Dedicated LED flashing task
;
do
      toggle LEDPin
      pause FlashSpeed
loop
 
Top