# Imports para led y tiempo
from machine import Pin
from time import sleep
# Variables para botón y led
led = Pin(12, Pin.OUT)
botonOn = Pin(15, Pin.IN, Pin.PULL_UP)
botonOff = Pin(4, Pin.IN, Pin.PULL_UP)
botonOnOff = Pin(16, Pin.IN, Pin.PULL_UP)
# Declarar el estado del led
led_state = False
# Definir función que intercale el encendido y el apagado
def toggle(pin):
global led_state
led_state = not led_state
led.value(led_state)
# Definir una función que encienda el led
def on(pin):
state = True
led.value(state)
# Definir una función que apague el led
def off(pin):
state = False
led.value(state)
# Instrucción que s elanza cuando se presiona el botón
botonOn.irq(trigger=Pin.IRQ_FALLING, handler=on)
botonOff.irq(trigger=Pin.IRQ_FALLING, handler=off)
botonOnOff.irq(trigger=Pin.IRQ_FALLING, handler=toggle)
while True:
pass