​ ​ ​ ​ Latch program not working
Results 1 to 3 of 3

Thread: Latch program not working

  1. #1
    New Member
    Join Date
    Dec 2017
    Location
    USA
    Posts
    25

    Default Latch program not working

    Hello,

    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

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

  2. #2
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    23,884

    Default

    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.

  3. #3
    Senior Member
    Join Date
    Jan 1970
    Location
    Nova Scotia, Canada
    Posts
    2,632

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •