import machine
#configurar el pin led interno como salida
LED = machine.Pin(25,machine.Pin.OUT)
Button = machine.Pin(0,machine.Pin.IN,machine.Pin.PULL_DOWN)
LEDState = False
#Este controlador IRQ alterna la variable que usamos para encender el LED. Debería, pero no verifica qué pin elevó la IRQ, ya que solo tenemos 1 pin conectado.
def ButtonIRQHandler (pin):
global LEDState
if LEDState == True:
LEDState = False
else:
LEDState = True
#Configure la IRQ y conéctela al controlador.
Button.irq (trigger = machine.Pin.IRQ_RISING, handler = ButtonIRQHandler)
#Ahora haga un bucle y encienda el LED con el estado del LED
while True:
LED.value(Button.value())