import time
from utime import sleep
from utime import ticks_ms
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
from machine import Pin
led = Pin(17, Pin.OUT | Pin.IN)
switch = Pin(22, Pin.IN)
first = 0
def handler(pin):
global first
now = ticks_ms()
if now - first < 500:
return
first = now
sleep(0.1)
if switch.value() != 1:
return
print('OK')
if led.value() == 1:
led.value(0)
print('NO')
else:
led.value(1)
switch.irq(handler, Pin.IRQ_RISING)
while True:
sleep (1)