from machine import Pin
from time import sleep
# Configuración de LEDs y botón
led_verde = Pin(2, Pin.OUT) # LED verde en GP2
led_rojo = Pin(3, Pin.OUT) # LED rojo en GP3
led_amarillo = Pin(4, Pin.OUT) # LED amarillo en GP4
boton = Pin(5, Pin.IN, Pin.PULL_DOWN) # Botón en GP5
# Clave correcta
CLAVE_CORRECTA = "1234"
# Variables
intentos = 0
bloqueado = False
def pedir_clave():
global intentos, bloqueado
if bloqueado:
print("Sistema bloqueado. Espere...")
return
clave = input("Ingrese la clave de acceso: ")
if clave == CLAVE_CORRECTA:
print("✅ Acceso permitido")
led_verde.on()
sleep(2)
led_verde.off()
intentos = 0 # Reinicia intentos
else:
print("❌ Clave incorrecta")
led_rojo.on()
sleep(1)
led_rojo.off()
intentos += 1
if intentos >= 3:
print("⚠️ 3 intentos fallidos. Sistema bloqueado por 10 segundos.")
led_amarillo.on()
bloqueado = True
sleep(10)
bloqueado = False
led_amarillo.off()
intentos = 0 # Reinicia intentos
print("💡 Sistema listo. Presione el botón para acceder.")
# Bucle principal
while True:
if boton.value() == 1:
pedir_clave()
while boton.value() == 1:
sleep(0.1) # Espera a que suelte el botón
sleep(0.1)