Skip to content

bdubs-astro/uPy_Debounce_Switch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

uPy_Debounce_Switch

Debounce a switch using interrupts.


Creates an interrupt handler that's called when the switch pin changes state (i.e., rising or falling edge trigger). If a debounce cycle has not already been started, the handler creates a one-shot timer. While this timer is running, any additional interrupts are ignored. After the timer expires, the desired action is taken (i.e., the sw_callback function is called), and the debounce cycle is cleared so it can begin again.

switch.irq(handler=sw_event, trigger=Pin.IRQ_FALLING|Pin.IRQ_RISING)

debounce_timer.init(mode=Timer.ONE_SHOT, period=debounce_delay, callback=debounce_clear)

Resources:

https://docs.micropython.org/en/latest/library/machine.Pin.html?highlight=pin#machine.Pin

https://docs.micropython.org/en/latest/library/machine.Timer.html



https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html


Digital Inputs: Pullup vs. Pulldown Resistors