from machine import Pin, PWM
from utime import sleep
# Configuración de los pines
led = PWM(Pin(23), freq=1000)
boton_aumentar = Pin(18, Pin.IN, Pin.PULL_DOWN)
boton_disminuir = Pin(19, Pin.IN, Pin.PULL_DOWN)
# Variables para la intensidad de brillo del LED
duty_cycle = 0 # Intensidad de brillo inicial (0%)
step = 100 # Aumento/Disminución
# Función para actualizar la intensidad de brillo del LED
def update_led():
led.duty(duty_cycle)
print(f"Intensidad del LED actualizada: {duty_cycle}/1023")
# Bucle principal
while True:
if boton_aumentar.value() == 1:
if duty_cycle + step <= 1023:
duty_cycle += step
update_led()
print("boton_aumentar presionado: Aumentando intensidad.")
else:
print("Intensidad máxima!!!")
sleep(0.2) # Para evitar exceso de repeticiones del boton
if boton_disminuir.value() == 1:
if duty_cycle - step >= 0:
duty_cycle -= step
update_led()
print("boton_disminuir presionado: Bajando Disminuyendo intensidad.")
else:
print("Intensidad mínima!!!")
sleep(0.1) # Para evitar exceso de repeticiones del boton