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: time.sleep(delay) if p_in() == 1: utime.sleep_ms(1000) print("--> Button pressed one time") utime.sleep_ms(1000) machine.reset() for i in range(2): _thread.start_new_thread(th_rst, (i + 1, i)) -
This post is deleted!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login