short press vs. long press button (pin.IN)

  • Hello together, I need your ideas ;-)

    I use the P4 to reset the board by pressing a button.
    but I want to use the button with multiple functions.

    in example: if I press the button short (1 Second) board restart
    if I press the button 10 seconds I want to do another action. (like deleting a file with os.remove('config.json')

    returns of P4 is 0 & 1

    #PIN4 to PWR_PYM
    machine.pin_deepsleep_wakeup(['P4'], mode=machine.WAKEUP_ANY_HIGH, enable_pull=True)
    # make `P4` an input with the pull-up enabled
    p_in = Pin('P4', mode=Pin.IN, pull=Pin.PULL_DOWN)
    def th_rst(delay, id):
        while True:
            if p_in() == 1:
                print("--> Button pressed one time")
    for i in range(2):
        _thread.start_new_thread(th_rst, (i + 1, i))

  • This post is deleted!

Log in to reply

Pycom on Twitter