from machine import Pin
from utime import sleep
btn = Pin(15, Pin.IN, Pin.PULL_DOWN)
led = Pin(25, Pin.OUT)
# Variable para almacenar el estado del LED
led_state = False
# Variable para almacenar el estado anterior del botón
prev_btn_state = 0
while True:
# Leer el estado actual del botón
btn_state = btn.value()
# Detectar cambio de estado del botón
if btn_state == 1 and prev_btn_state == 0:
# Cambiar el estado del LED
led_state = not led_state
# Actualizar el estado del LED
if led_state:
led.on()
else:
led.off()
# Actualizar el estado anterior del botón
prev_btn_state = btn_state
# Pequeña pausa para evitar rebotes
sleep(0.1)