from machine import Pin, Timer
import time
led = Pin(0, Pin.OUT)
boton = Pin(16, Pin.IN, Pin.PULL_UP)
tim1 = Timer()
def tempo1(tim1):
led.toggle()
def fun_boton(boton):
if boton.value() == 0:
led.on()
tim1.init(freq=5, mode=Timer.PERIODIC, callback=tempo1)
else:
led.off()
tim1.deinit()
boton.irq(trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING, handler=fun_boton)
while True:
pass