Micropython implementation of a debounced button. Tested to work well with the Raspberry Pi Pico.
- Connect a button to ground and any pin of the microcontroller
- Upload
button.pyto the microcontroller - Use according to the below example script
- Simple and easy to use
- Interrupt/Callback based -> no polling
- Supports short and long presses
- Software debounce -> no additional hardware required
from button import Button
button_pin = 18
def click():
print("Short click")
def long():
print("Long press")
b = Button(button_pin, click, long)Debouce time and long-press duration can be modified using:
b = Button(pin_number, callback, long_press_callback=None, debounce_time_ms=50, long_press_duration_ms=2000)