question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation Improvement: Pushbutton Suppress argument

See original GitHub issue

Hi, This library is awesome. I couldn’t believe how simple it was to create tasks and to use buttons. I was able to do in hours what took me days/weeks in Arduino. Also, kudos that there is documentation on Github!

However, it took me a few tries to figure out how to implement multi-function push buttons (single, long, and double). I think as micropython grows in popularity, a lot more students, non-native speakers, and people who are not computer scientists will use this library. I wonder if the documentation could be expanded to offer more “goal-oriented how to’s”. The trouble I had was that I initially set up a press_func, and then wanted to add more functionality from there. I’m sure many people will take a similar approach. After creating more tasks which used different methods, I began testing. Then I saw my console log fill up with undesired behavior. I’m sure many others will also get frustrated to see that when they try to set up double or long presses, also get short presses. It took me a few several reads, and a lot of experimenting, to figure out how to modify my code to use the suppress function correctly. For me, the concept of “suppress” didn’t really enter my mind. https://github.com/peterhinch/micropython-async/blob/master/v3/docs/DRIVERS.md#411-the-suppress-constructor-argument

This would probably make for a great tutorial in a book, an article on a blog, or a youtube video, but why not expand this technical documentation here to make it more accessible to new users? Now, I’m not sure if there is a style guide that this project adheres to, or if the maintainers are against including animated gifs of both the console and a fritzing-style breadboard pressing a button. But here’s my suggestion for a code snippet:

(4.1.1.1) Multi-Function Push Buttons Implementation

This code snippet demonstrates how to use which code to interpret push button single (release), double (presses), and long presses together without undesired events getting triggered. Setting the “suppress=True” argument is critical to making these events cooperate.

from machine import Pin
import uasyncio
import Pushbutton

btn = Pin(<your chosen pin>, Pin.IN, Pin.PULL_UP, suppress=True) # Assumes a Raspberry Pi Pico
pb = Pushbutton(btn)

async def short_press():
    print("SHORT")
    await uasyncio.sleep_ms(1000)
    
async def double_press():
    print("DOUBLE")
    await uasyncio.sleep_ms(1000)

async def long_press():
    print("LONG")
    await uasyncio.sleep_ms(1000)

async def main():
    q = queue.Queue()
    short_press = pb.release_func(short_press)
    double_press = pb.double_func(double_press)
    long_press = pb.long_func(long_press)
    while True:
        await uasyncio.sleep_ms(1000)```

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
peterhinchcommented, Feb 3, 2022

OK, I’ll go with that. I’ve pushed an update, with a few very minor tweaks to the wording and formatting.

Thank you for the contribution.

1reaction
peterhinchcommented, Feb 2, 2022

I have added the above script here. Thanks for the suggestion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parameter input field followed by push button in same line of ...
I have an issue in designing a selection screen such that my requirement is to have a Input parameter field followed by a...
Read more >
Disable unique prefix matches for argparse and optparse
When I use Python's argparse or optparse command line argument parser, any unique prefix of an argument is considered valid, ...
Read more >
Using Action Buttons - R Shiny - RStudio
Create an action button with actionButton() and an action link with actionLink() . Each of these functions takes two arguments: inputId - the...
Read more >
C++ Core Guidelines - GitHub Pages
The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++.
Read more >
Button | Android Developers
Use WindowInsetsController#hide(int) with Type#statusBars() instead. ... behaves exactly as sendAccessibilityEvent(int) but takes as an argument an empty ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found