import machine as mc
from utime import sleep, sleep_ms
print("Hello, Pi Pico!")
push_bt = mc.Pin(16, mc.Pin.IN, mc.Pin.PULL_UP)
led = mc.Pin(15, mc.Pin.OUT)
# global value
button_pressed = False
def wait_pin_change(pin):
# wait for pin to change value
# it needs to be stable for a continuous 20ms
cur_value = pin.value()
active = 0
while active < 5:
if pin.value() != cur_value:
active += 1
else:
active = 0
sleep_ms(1)
# Interrupt Service Routine for Button Pressed Events - with no debounce
def button_pressed(change):
global button_pressed
button_pressed = True
# here is how we associate the falling value on the input pin with the callback function
push_bt.irq(handler=button_pressed, trigger=mc.Pin.IRQ_FALLING)
while True:
if (button_pressed == True):
print("button_pressed")
wait_pin_change(push_bt)
button_pressed = False
if (led.value() == 1):
led.off()
else:
led.on()
sleep(0.2)
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
r1:1
r1:2
led1:A
led1:C