print("Debouncing demo")
import machine as m
settling_time = 20 # Set to 1000 to see how does it work
p1=m.Pin(32,m.Pin.IN, m.Pin.PULL_UP)
p2=m.Pin(33,m.Pin.IN, m.Pin.PULL_UP)
t1 = m.Timer(1)
t2 = m.Timer(2)
def t1_cb(t):
print('pin 1 change to ', p1.value())
# Of course, you may add here your own code
def p1_cb(p):
t1.init(mode=m.Timer.ONE_SHOT, period=settling_time, callback=t1_cb)
def t2_cb(t):
print('pin 2 change to ', p2.value())
# Of course, you may add here your own code
def p2_cb(p):
t2.init(mode=m.Timer.ONE_SHOT, period=settling_time, callback=t2_cb)
p1.irq(trigger=m.Pin.IRQ_RISING | m.Pin.IRQ_FALLING, handler=p1_cb)
p2.irq(trigger=m.Pin.IRQ_RISING | m.Pin.IRQ_FALLING, handler=p2_cb)