Latch program not working


Trying to create a latch that works like this. Press the trigger switch and the output led should come on an stay on press the trigger again and the led should go out. But if the trigger is held down or press and not released I would like for the circuit to ignored that and only toggle when the trigger is pressed and released . Below is the start of my program but getting error with the if the statement .

symbol sw = 1 ' Trigger input switch
symbol Led= 2 ' output led for indication only
' Program sequence press the switch release the switch led should latch or stay on press the trigger again the led should go out. Once the trigger is press and if for some reason the trigger is not released the led should stay on unit the trigger is release.

' Getting error at line 8 not sure why

if sw=1 then Top:
toggle Led
pause 500
goto Top:


Technical Support
Staff member
To read an input you need to read a 'pin' variable.

Change "symbol sw = 1" to "symbol sw = pin1" and it should at least pass syntax check.


Senior Member
It looks like your switch is active low (0 when depressed); is this what you intend?

After making the change suggested by hippy, add this line before "goto Top" (which need not end with a colon):

Do : Loop while sw = 0

This is two statements (note the ":" statement separator token) which are usually placed together on a single line. With that included, your code will not return to "Top" until the button (active low) has been released.