from machine import Pin, ADC, PWM
import time
# Configuración de pines
pot = ADC(27) # Pin ADC para el potenciómetro
led = Pin(16, Pin.OUT) # Pin del LED
boton = Pin(15, Pin.IN, Pin.PULL_DOWN) # Botón con resistencia pull-down
while True:
# Esperar hasta que se presione el botón
if boton.value() == 1:
print("Botón presionado, iniciando bucle...")
led.value(1) # Encender el LED
while True:
lectura = pot.read_u16() # Leer el valor del potenciómetro
# Condición para apagar el LED
if lectura >= 40000:
print("Condición alcanzada, apagando LED...")
led.value(0) # Apagar el LED
tiempo_inicio = time.ticks_ms() # Tiempo inicial
while True:
# Verificar si han pasado 20 segundos
if time.ticks_diff(time.ticks_ms(), tiempo_inicio) > 20000:
print("¡Éxito! El valor se mantuvo por 20 segundos.")
break
# Leer el potenciómetro durante la espera
lectura_durante_espera = pot.read_u16()
if lectura_durante_espera < 40000:
print("Error: El valor cambió antes de los 20 segundos.")
break
break # Salir del bucle de condiciones
# Pequeño retraso para evitar lecturas excesivas
time.sleep_ms(100)