How to exit this program once the button has been pressed?



  • Hello all,

    I am trying to get this code to exit once the button has been pressed and cant get it to work with break or exit.

    print("Here we go! Press CTRL+C to exit")
    try:
    while 1:
    device.loop()
    if device.is_connected():
    if int(button.getValue()):
    print("Button pressed!")
    device.send_state({"button": 1})
    time.sleep(3) # Debounce button press
    time.sleep(0.03)
    except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
    led._freeGpio()
    button._freeGpio()# cleanup all GPIO



  • Oh I forgot to mention it is an autorun program to start on boot.


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.