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.
I have tried doing:
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:
Thanks all.
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
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
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