Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

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

    Scheduled Pinned Locked Moved Discussion
    2 Posts 2 Posters 196 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      svonbentzel
      last edited by

      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))
      
      S 1 Reply Last reply Reply Quote 0
      • S Offline
        SmithM97 @svonbentzel
        last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0

        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
        • 1 / 1
        • First post
          Last post

        Pycom on Twitter

        Pycom