from machine import Pin
from utime import sleep
led = Pin(10, Pin.OUT)
sw = Pin(21, Pin.IN)
def sw_handler(pin):
if sw() == 0:
led.on()
sleep(0.2)
print("ON")
else:
led.off()
sleep(0.2)
print("OFF")
sw.irq(handler = sw_handler)