Cheque for IR signal during programme

jensmith25

Senior Member
I have been trying to improve code so that it will check for an IR signal on button press while the action is being carried out.

eg, I have a flashing light in a loop but I want to exit the loop early if another button is pressed. So far, the only way I can get it to work consistently is to set a time for the loop.

Code:
swonright: ;switch on right indicators (right arrow)
	do 
	toggle B.4
	pause 500
	inc b2
	loop while b2 < 10		'otherwise loop 
	low B.4
	goto main
I have tried doing:
Code:
swonright: ;switch on right indicators (right arrow)
	do 
	toggle B.4
	pause 500
	inc b2
	loop until pinC.4 = 0 
	low B.4
	goto main
and that seemed to work initially and then became erratic. I have 3 of these flashing effects in the programme - it's for a motorbike model so they are left and right indicators and hazard warning lights.

Ideally I'd like to set the loop going with no time limit and then when another button is pressed the loop exits.

Is there a way to do this easily? If not I'll leave it as is.

For completeness:
Code:
swonright: ;switch on right indicators (right arrow)
	do 
	toggle B.4
	pause 500
	inc b2
	loop while b2 < 10		'otherwise loop 
	low B.4
	goto main
	
swoffind: ;switch off left and right indicators (tent symbol)
	low B.4, B.5
	goto main
	
swonleft: ;switch on left indicators (left arrow)
	do
	toggle B.5
	pause 500
	inc b3
	loop while b3 < 10		'otherwise loop 
	low B.5
	goto main
	
swonhaz: ;switch on hazards (up arrow)
	do
	high B.4, B.5
	pause 500
	low B.4, B.5
	pause 500
	inc b4
	loop while b4 < 10		'otherwise loop 
	goto main
Thanks all.
 

hippy

Ex-Staff (retired)
I have tried doing ... loop until pinC.4 = 0 ... and that seemed to work initially and then became erratic.
That sounds like there may be a hardware issue or button bounce affecting things.

It's probably best to resolve that first before trying to do anything else which relies on similar. If it's erratic for the simple case then it will likely be erratic for more complicated cases.
 

jensmith25

Senior Member
That sounds like there may be a hardware issue or button bounce affecting things.

It's probably best to resolve that first before trying to do anything else which relies on similar. If it's erratic for the simple case then it will likely be erratic for more complicated cases.
I think that unlikely because all the other simple commands are working fine. Switching on and off the other lights is no problem and happens immediately on button press on the remote.

The e-mail I got telling me you had replied also had some code in it - that doesn't seem to be working either. The indicator just keeps flashing.
 

hippy

Ex-Staff (retired)
That sounds like there may be a hardware issue or button bounce affecting things.

It's probably best to resolve that first before trying to do anything else which relies on similar. If it's erratic for the simple case then it will likely be erratic for more complicated cases.
I think that unlikely because all the other simple commands are working fine. Switching on and off the other lights is no problem and happens immediately on button press on the remote.
I think you might have to explain what hardware you have, what your circuit looks like, and perhaps post your full code.

I had assumed you were using physical buttons, but it seems you may mean buttons on an IR remote.

If so, and you are just using pinC.4 to detect the presence or absence of IR then that could become erratic if there is other IR present in the vicinity. Holding an IR remote button may also cause multiple button pushes to be seen which may make things erratic.


The e-mail I got telling me you had replied also had some code in it - that doesn't seem to be working either. The indicator just keeps flashing.
I edited that out because, on second reading, it did not seem to do what you had asked for. My code used one activation of pinC.4 to start the loop, a second activation to stop it. Re-reading it seemed you wanted two separate buttons, one to start one to stop.

The code worked for me when I simulated it, so this also suggests some hardware or related issue to me.
 

jensmith25

Senior Member
Hardware:

Picaxe 14m2 project board
IR sensor with usual capacitor and resistor to input C.4
Picaxe supplied TV style remote

Outputs B.0-B.6 with LEDs

Standard circuit, nothing fancy. I am using a IR receiver module rather than what I usually do which is wire up the components individually to the PCB but it's working for everything else. This one: http://www.geeetech.com/wiki/index.php/IR_Transmitter_and_Receiver_Kit

so yes, it is IR button presses rather than physical buttons.



Code:
#Picaxe 14M2
;IR lighing kit for Harley Davidson Motorbike © JS Miniatures/Small Scale Lights 2016

; Output B.0: Headlight hi beam 
; Output B.1: Brake lights x 2 (controlled from contact switches)
; Output B.2: Headlight low beam & Rear lights (dimmer with bigger resistor)
; Output B.3: Console light
; Output B.4:  Indicators x 4 - flashing right as indicators and all 4 for hazard lights
; Output B.5: Indicators x 4 - flashing left as indicators and all 4 for hazard lights

	let b2 = 1 'reset variable b2 to 1
	let b3 = 1 'reset variable b3 to 1
	let b4 = 1 'reset variable b4 to 1
	let b5 = 1 'reset variable b5 to 1
	let b6 = 1 'reset variable b6 to 1
	let b7 = 1 'reset variable b7 to 1
main:
	irin [1000,main],C.4,b0 ;wait for new signal
	if b0 = 0 then swon1 ;switch on 1, headlight hi beam
	if b0 = 1 then swon2 ;switch on 2, brake lights
	if b0 = 2 then swon3 ;switch on 3, headlight low beam and rear lights
	if b0 = 3 then swon4 ;switch on 4, console light
	
	if b0 = 18 then swonright ;switch on right indicators (right arrow)
	if b0 = 19 then swonleft ;switch on left indicators (left arrow)
	if b0 = 54 then swoffind ;switch off indicators (tent symbol)
 
	if b0 = 16 then swonhaz ;switch on hazard lights (up arrow)
	if b0 = 17 then swoffhaz ;switch off hazard lights (down arrow)
	
	if b0 = 5 then swoff1  ;switch off 6, headlight hi beam
	if b0 = 6 then swoff2  ;switch off 7, brake lights
	if b0 = 7 then swoff3  ;switch off 8, headlight low beam and rear lights
	if b0 = 8 then swoff4 ;switch off 9, console light
	
	if b0 = 21 then swondemo   ;enter demo mode
	
	if b0 = 9 then swoffall ;switch off all lights 0
	goto main
	
swon1: ;headlight hi beam
	high B.0
	goto main
	
swoff1: ;headlight hi beam
	low B.0
	goto main
	
swon2: ;brake lights
	high B.1
	goto main
	
swoff2: ;brake lights
	low B.1
	goto main
	
swon3: ;headlight low beam and rear lights
	low B.0
	high B.2
	goto main
	
swoff3: ;headlight low beam and rear lights
	low B.2
	goto main
	
swon4: ;console light
	high B.3
	goto main
	
swoff4: ;console light
	low B.3
	goto main
	
swonright: ;switch on right indicators (right arrow)
	do 
	toggle B.4
	pause 500
	inc b2
	loop while b2 < 10		'otherwise loop 
	low B.4
	goto main

swoffind: ;switch off left and right indicators (tent symbol)
	low B.4, B.5
	goto main
	
swonleft: ;switch on left indicators (left arrow)
	do
	toggle B.5
	pause 500
	inc b3
	loop while b3 < 10		'otherwise loop 
	low B.5
	goto main
	
swonhaz: ;switch on hazards (up arrow)
	do
	high B.4, B.5
	pause 500
	low B.4, B.5
	pause 500
	inc b4
	loop while b4 < 10		'otherwise loop 
	goto main
	
swoffhaz: ;switch off hazards (down arrow)
	low B.4, B.5
	goto main	
	
swoffall: ;switch off all lights
	low B.0, B.1, B.2, B.3, B.4, B.5
	goto main
	
swondemo: ;switch on demo mode (brake lights are on a contact switch)
	high B.2, B.3 ;turn on running lights (low beam and rear lights) and console light
	pause 3000
	low B.2 ;turn off low beam
	high B.0, B.1 ;turn on hi beam & brake lights
	pause 5000
	low B.0, B.1 ;turn off high beam & brake lights
	high B.2 ;turn low beam back on

	do
	  high B.4			'turn on the indicator on B.4
	  pause 500			'wait 1 second
	  low B.4			'turn off the LED on B.4
	  pause 500			'wait 1 second
	  inc b5			'increment the loop counter
	loop while b5 < 10		'otherwise loop 
	do
	  high B.5			'turn on the indicator on B.4
	  pause 500			'wait 1 second
	  low B.5			'turn off the LED on B.4
	  pause 500			'wait 1 second
	  inc b6			'increment the loop counter
	loop while b6 < 10		'otherwise loop 
	do
	  high B.4, B.5			'turn on the hazards on B.4
	  pause 500			'wait 1 second
	  low B.4, B.5			'turn off hazards on B.4
	  pause 500			'wait 1 second
	  inc b7			'increment the loop counter
	loop while b7 < 10		'otherwise loop 
	
	low B.0, B.1, B.2, B.3, B.4, B.5 ;turn off all lights
	goto main
	
End
 

hippy

Ex-Staff (retired)
Thanks. So what you are wanting to do is detect IR key presses while also looping and toggling a LED.

You could possibly use an IRIN with timeout to replace the PAUSE. That is probably the best way.

Reading the pinC.4 to determine presence of IR can work but, as you have found, can be erratic.

That's because a remote may send data while a key is held and the data sent isn't a simple pulse. How you had it, the IR has to be present in a very short period after the half second PAUSE. If it's not present there won't be another check for a further half second.
 

jensmith25

Senior Member
Thanks Hippy.

Is this right because the lights are coming on on remote button press but not staying on to do the flash cycle so I think something must be wrong. Do I need a new variable?

Code:
swonleft: ;switch on left indicators (left arrow)
	do
	toggle B.5
	irin [500],C.4,b0 ;wait for new signal
	inc b3
	loop while b3 < 10		'otherwise loop 
	low B.5
	goto main
 

hippy

Ex-Staff (retired)
You need to handle the IRIN timeout to continue the loop or abort the loop when it doesn't. Perhaps something like this, untested ...

Code:
swonleft: ;switch on left indicators (left arrow)
	do
	toggle B.5
	irin [500,swonleft_timeout],C.4,b0 ;wait for new signal
	goto swonleft_exit
swonleft_timeout:
	inc b3
	loop while b3 < 10		'otherwise loop 
swonleft_exit:
	low B.5
	goto main
Also, if the lights aren't staying on, then it might be because b3 isn't initialised on entry, is set to 10 or more so exits almost immediately.
 

jensmith25

Senior Member
Can't get that working either. It's fine until you press a second button then falls over.

It's ok, I'll just go back to what I had originally without worrying about trying to exit the loop.
 

hippy

Ex-Staff (retired)
Can't get that working either. It's fine until you press a second button then falls over.
On what way does it fall over ?

Receiving an IR button push should cause the program to behave as if the w3<10 loop had completed, no more and no less.

If everything is fine when the code complete with w3<10 it should be fine when it completes after an IR button press. The only difference might be that IR is still active when the code reaches the main and the IRIN there.

If that's causing the problem you might have to rework the exit on second press to wait until no IR is being received before continuing to main.

Code:
swonleft: ;switch on left indicators (left arrow)
	do
	toggle B.5
	irin [500,swonleft_timeout],C.4,b0 ;wait for new signal
        Do
	  irin [500,swonleft_exit],C.4,b0
	Loop
swonleft_timeout:
	inc b3
	loop while b3 < 10		'otherwise loop 
swonleft_exit:
	low B.5
	goto main
 

jensmith25

Senior Member
Thanks hippy. I'll have another go at it. The lights were only coming on when I pressed the button, for a fraction of a second and then off.

I'm getting another random error now on B.0 despite putting everything back the way it was so I suspect something odd is going on. I'll see if I can sort that and then try your code again. It's been one of those days so I suspect I'm maybe missing something simple. I've not changed anything on B.0 but now it lights when you press the button then stops.
 

erco

Senior Member
IRIN is a very flexible command with its timeout and jump-to options. One thing to be aware of is that some IR remote button functions vary slightly. When held down, the digit buttons will send a short burst then stop, requiring a release before any more can be sent. Other buttons will transmit continuously when held down, until a long timeout (15-20 seconds) shuts down the remote. This timeout may be to save batteries when we sit on it. :)

So digit buttons might not appear to work if your program isn't looking for them exactly when the remote is sending.
 

jensmith25

Senior Member
Thanks Erco for that info. I didn't know that. The flashing lights are all on 'other' non digit buttons and the static lights are on digit buttons.
 

hippy

Ex-Staff (retired)
Code:
main:
	irin [1000,main],C.4,b0 ;wait for new signal
The timeout and jump to 'main' is redundant there, may even cause problems should a single IR command be received while the IRIN is timing out and going back to 'main'. It would be better to use a simple -

Code:
main:
	irin C.4,b0 ;wait for new signal
 

jensmith25

Senior Member
On what way does it fall over ?

Receiving an IR button push should cause the program to behave as if the w3<10 loop had completed, no more and no less.

If everything is fine when the code complete with w3<10 it should be fine when it completes after an IR button press. The only difference might be that IR is still active when the code reaches the main and the IRIN there.

If that's causing the problem you might have to rework the exit on second press to wait until no IR is being received before continuing to main.

Code:
swonleft: ;switch on left indicators (left arrow)
	do
	toggle B.5
	irin [500,swonleft_timeout],C.4,b0 ;wait for new signal
        Do
	  irin [500,swonleft_exit],C.4,b0
	Loop
swonleft_timeout:
	inc b3
	loop while b3 < 10		'otherwise loop 
swonleft_exit:
	low B.5
	goto main
It's still not working. The light only come on briefly when you press the remote button and then goes off again as though it's immediately going to exit without going through the flashing cycle.
Otherwise everything is now working fine now that I've switched it to irin C.4, b0

I've tried switching it to digits rather than symbols on the remote to see if that was the issue but didn't make any difference.

I think I'll just have to forget trying to interrupt the loop and just have it timed for "x" number of flashes.
 

jensmith25

Senior Member
I've discovered an issue that might be causing some of the problems. The download cable being plugged into my PC is affecting the results. If it's plugged in everything works fine. If it's not then it some lights don't work.

I can't see any obvious shorts but what is the likely issue with this - presumably something to do with the download socket or 10k/22k resistors?

EDIT: I've checked the PCB and I can't find any shorts. The downloads are working fine to the chip so I'm not sure what's going wrong but the LED on B.0 ie the download pin doesn't work properly if the download cable isn't connected to my laptop.
 
Last edited:

hippy

Ex-Staff (retired)
It's still not working. The light only come on briefly when you press the remote button and then goes off again as though it's immediately going to exit without going through the flashing cycle.
That could be a similar issue to what may have been happening on the second key push causing it to behave oddly there.

After the initial key push you might need to wait for there not to be a key push before checking for a further key push to exit the loop. Otherwise a repeated first key push will be treated as the second key push.

You can add SERTXD commands to help track the flow through your code and display values useful for determining what the code is doing.

You can also simulate the code though simulated hardware such as an IR remote may not act exactly as real hardware would.

I've discovered an issue that might be causing some of the problems. The download cable being plugged into my PC is affecting the results. If it's plugged in everything works fine. If it's not then it some lights don't work.
Not sure what's wrong there but would guess it's some issue with the download connections or similar, perhaps the serial in floating, perhaps the 10K on the wrong side of the 22K.

Post your circuit diagram and photos of both sides of your board and members can take a look at those. The more info you can provide the easier it is for others to help resolve the problem.
 

jensmith25

Senior Member
Not sure what's wrong there but would guess it's some issue with the download connections or similar, perhaps the serial in floating, perhaps the 10K on the wrong side of the 22K.

Post your circuit diagram and photos of both sides of your board and members can take a look at those. The more info you can provide the easier it is for others to help resolve the problem.
Looks like it was a solder joint issue. They all basically looked ok and checked out on the multimeter but I tried re-soldering a few around the download socket and hey presto it seems to be working fine now.

It is the Axe117 board so the actual hardware was in the right place at least.

Thanks hippy, it's been one of those weeks!

EDIT: now an intermittent issue with the indicators.
 
Last edited:

jensmith25

Senior Member
That could be a similar issue to what may have been happening on the second key push causing it to behave oddly there.

After the initial key push you might need to wait for there not to be a key push before checking for a further key push to exit the loop. Otherwise a repeated first key push will be treated as the second key push.

You can add SERTXD commands to help track the flow through your code and display values useful for determining what the code is doing.

You can also simulate the code though simulated hardware such as an IR remote may not act exactly as real hardware would.
Ok, that makes sense. I'm tempted not to risk trying to change it again incase of further issues as the chap is happy with it as is, I was just trying to improve it.
 

hippy

Ex-Staff (retired)
I'm tempted not to risk trying to change it again incase of further issues as the chap is happy with it as is, I was just trying to improve it.
Save what you have as a stable version; you can then change things with an escape plan in place. If it works save that and move on, if it doesn't work then you can always go back to what was working, that stable version.

It is possibly worth trying to get it to work perfectly now, because someone may ask for the same in the future but want it working better than it currently does. It is easier to resolve issues while they are still fresh in one's mind.
 

jensmith25

Senior Member
Currently I'm finding that everything works ok unless I switch on B.3 then everything become erratic. That then causes the indicators to only flash once and then nothing. Everything else appears to be working ok but I can't see anything that would conflict in the code.

I tried moving the indicators to the + and - buttons incase using the arrow buttons was the problem but that hasn't helped either.

Code:
#Picaxe 14M2
;IR lighing kit for Harley Davidson Motorbike © JS Miniatures/Small Scale Lights 2016

; Output B.0: Headlight hi beam 
; Output B.1: Brake lights x 2 (controlled from contact switches)
; Output B.2: Headlight low beam & Rear lights (dimmer with bigger resistor)
; Output B.3: Console light
; Output B.4:  Indicators x 4 - flashing right as indicators and all 4 for hazard lights
; Output B.5: Indicators x 4 - flashing left as indicators and all 4 for hazard lights

	let b2 = 1 'reset variable b2 to 1
	let b3 = 1 'reset variable b3 to 1
	let b4 = 1 'reset variable b4 to 1
	let b5 = 1 'reset variable b5 to 1
	let b6 = 1 'reset variable b6 to 1
	let b7 = 1 'reset variable b7 to 1
main:
	irin C.4,b0 ;wait for new signal
	if b0 = 0 then swon1 ;switch on 1, headlight hi beam
	if b0 = 1 then swon2 ;switch on 2, brake lights
	if b0 = 2 then swon3 ;switch on 3, headlight low beam and rear lights
	if b0 = 3 then swon4 ;switch on 4, console light
	
	if b0 = 11 then swonright ;switch on right indicators (minus)
	if b0 = 98 then swonleft ;switch on left indicators (plus)
 
	if b0 = 4 then swonhaz ;switch on 5 hazard lights
	
	if b0 = 5 then swoff1  ;switch off 6, headlight hi beam
	if b0 = 6 then swoff2  ;switch off 7, brake lights
	if b0 = 7 then swoff3  ;switch off 8, headlight low beam and rear lights
	if b0 = 8 then swoff4 ;switch off 9, console light
	
	if b0 = 21 then swondemo   ;enter demo mode
	
	if b0 = 9 then swoffall ;switch off all lights 0
	goto main
	
swon1: ;headlight hi beam
	high B.0
	goto main
	
swoff1: ;headlight hi beam
	low B.0
	goto main
	
swon2: ;brake lights
	high B.1
	goto main
	
swoff2: ;brake lights
	low B.1
	goto main
	
swon3: ;headlight low beam and rear lights
	low B.0
	high B.2
	goto main
	
swoff3: ;headlight low beam and rear lights
	low B.2
	goto main
	
swon4: ;console light
	high B.3
	goto main
	
swoff4: ;console light
	low B.3
	goto main
	
swonright: ;switch on right indicators (right arrow)
	do 
	high B.4
	pause 500
	low B.4
	pause 500
	inc b2
	loop while b2 < 10		'otherwise loop 
	goto main
	
swonleft: ;switch on left indicators (left arrow)
	do
	high B.5
	pause 500
	low B.5
	pause 500
	inc b3
	loop while b3 < 10		'otherwise loop 
	goto main

swonhaz: ;switch on hazzard indicators (up arrow)
	do
	high B.4, B.5
	pause 500
	low B.4, B.5
	pause 500
	inc b4
	loop while b4 < 10		'otherwise loop 
	goto main
	
swoffall: ;switch off all lights
	low B.0, B.1, B.2, B.3, B.4, B.5
	goto main
	
swondemo: ;switch on demo mode (brake lights are on a contact switch)
	high B.2, B.3 ;turn on running lights (low beam and rear lights) and console light
	pause 3000
	low B.2 ;turn off low beam
	high B.0, B.1 ;turn on hi beam & brake lights
	pause 5000
	low B.0, B.1 ;turn off high beam & brake lights
	high B.2 ;turn low beam back on

	do
	  high B.4			'turn on the indicator on B.4
	  pause 500			'wait 1 second
	  low B.4			'turn off the LED on B.4
	  pause 500			'wait 1 second
	  inc b5			'increment the loop counter
	loop while b5 < 10		'otherwise loop 
	do
	  high B.5			'turn on the indicator on B.4
	  pause 500			'wait 1 second
	  low B.5			'turn off the LED on B.4
	  pause 500			'wait 1 second
	  inc b6			'increment the loop counter
	loop while b6 < 10		'otherwise loop 
	do
	  high B.4, B.5			'turn on the hazards on B.4
	  pause 500			'wait 1 second
	  low B.4, B.5			'turn off hazards on B.4
	  pause 500			'wait 1 second
	  inc b7			'increment the loop counter
	loop while b7 < 10		'otherwise loop 
	
	low B.0, B.1, B.2, B.3, B.4, B.5 ;turn off all lights
	goto main
	
End
EDIT: Switching off and going through various scenarios it seems as though it works fine the first run through but then becomes erratic and it's always the B.4 & B.5 indicators that won't do anything other than flash once. Re-setting and they're fine again and demo mode runs through no problem. I don't know what's going wrong.
 
Last edited:

hippy

Ex-Staff (retired)
Switching off and going through various scenarios it seems as though it works fine the first run through but then becomes erratic and it's always the B.4 & B.5 indicators that won't do anything other than flash once. Re-setting and they're fine again and demo mode runs through no problem.
Sounds like that not initialising the loop counter variable I mentioned earlier. The value in the variable already at the exit value when the code is entered.

If you simulate the code you will see exactly that happening.

Note that your variable initialisation is before 'main' so only happens when the program starts, not every time you jump back to 'main'.
 

jensmith25

Senior Member
Sounds like that not initialising the loop counter variable I mentioned earlier. The value in the variable already at the exit value when the code is entered.

If you simulate the code you will see exactly that happening.

Note that your variable initialisation is before 'main' so only happens when the program starts, not every time you jump back to 'main'.
Thanks Hippy, moving the variables into 'main' seems to have solved the problem.

If that's working, saved and stable I'll see if I can do the other stuff again.
 

jensmith25

Senior Member
I found a way to make it mostly work - when you press a remote button it does exit but then you have to press the button again to get the next command started.

Code:
swonleft: ;switch on left indicators (minus)
	do
	toggle B.5
	pause 250
	irin [250,swonleft_timeout],C.4,b0 ;wait for new signal
        Do
        pause 250
	  irin [250,swonleft_exit],C.4,b0
	Loop
swonleft_timeout:
	inc b3
	loop while b3 < 20		'otherwise loop 
swonleft_exit:
	low B.5
	goto main
Can you have it so it jump to the correct command at exit of the loop or is this the best you can do? I tried adding another irin command at swonleft_exit
Code:
low B.5
pause 250
irin C.4, b0
goto main
but that didn't help.
 

hippy

Ex-Staff (retired)
Can you have it so it jump to the correct command at exit of the loop
Yes. When you have seen the key press which ends the loop, don't jump to main which waits for another key press, but jump to after that because you already have the key press.

You will probably need to rewrite your code so you are waiting for key presses and waiting for no key press in the correct places or you may end up back with the issue of code being executed but immediately exiting. Incomplete and untested ...

Code:
Main:
  Do
    Gosub CheckKeyPress
  Loop Until b0 = $FF
  Do
    Gosub CheckKeyPress
  Loop Until b0 <> $FF

Execute:
  If b0 = XXX Then TurnOn
  If b0 = YYY Then FlashLoop
  :
  Goto Main

TurnOn:
  High LED
  Goto [b]Main[/b]

FlashLoop:
  Do
    Toggle LED
    Gosub CheckKeyPress
  Loop Until b0 = $FF
  Do
    Toggle LED
    Gosub CheckKeyPress
  Loop Until b0 <> $FF
  Goto [b]Execute[/b]

CheckKeyPress:
  IrIn [500,TimedOut], IR_PIN, b0
  Return
TimedOut:
  b0 = $FF
  Return
And using #MACRO to make the main code more understandable ...

Code:
#Macro LoopUntilNoKeyPress
  Gosub CheckKeyPress
  Loop Until b0 = $FF
#EndMacro

#Macro LoopUntilKeyPress
  Gosub CheckKeyPress
  Loop Until b0 <> $FF
#EndMacro

Main:
  Do : LoopUntilNoKeyPress
  Do : LoopUntilKeyPress

Execute:
  If b0 = XXX Then TurnOn
  If b0 = YYY Then FlashLoop
  :
  Goto Main

TurnOn:
  High LED
  Goto Main

FlashLoop:
  Do
    Toggle LED
  LoopUntilNoKeyPress
  Do
    Toggle LED
  LoopUntilKeyPress
  Goto Execute

CheckKeyPress:
  IrIn [500,TimedOut], IR_PIN, b0
  Return
TimedOut:
  b0 = $FF
  Return
 
Last edited:
Top