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)
interruptor = Pin(25, Pin.IN)
led1 = Pin(26, Pin.OUT)
led2 = Pin(27, Pin.OUT)
# 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
# Parte 1:
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
# Parte 2: Control del interruptor y los 2 LEDs
estado_interruptor = interruptor.value()
if estado_interruptor:
led1.value(1) # Enciende LED1
sleep(0.2) # Para evitar exceso de repeticiones del boton
led2.value(0) # Apaga LED2
else:
led1.value(0) # Apaga LED1
sleep(0.2) # Para evitar exceso de repeticiones del boton
led2.value(1) # Enciende LED2