from machine import ADC, Pin, PWM
import time
from utime import sleep
# Definir los pines GPIO para el LED RGB
tempe = ADC(Pin(25))
led_red = Pin(21, Pin.OUT)
led_green = PWM(Pin(19), freq=1000)
led_blue = Pin(18, Pin.OUT)
pin_rojo = 2
pin_verde = 4
pin_azul = 5
pin_amarillo = 15
# Definir los pines para señales de entrada y salida
sw = ADC(Pin(34)) # Switch/pulsador
vrx = ADC(Pin(35)) # Eje X
vry = ADC(Pin(33)) # Eje Y
led_rojo = Pin(pin_rojo, Pin.OUT)
led_azul = Pin(pin_azul, Pin.OUT)
led_verde = Pin(pin_verde, Pin.OUT)
led_amarillo = Pin(pin_amarillo, Pin.OUT)
# Función para encender el LED RGB con un color específico
def encender_led_rgb(rojo, verde, azul, amarillo):
led_rojo.value(rojo)
led_verde.value(verde)
led_azul.value(azul)
led_amarillo.value(amarillo)
# Configurar la precisión y el ancho de bits de los ADC
vrx.atten(ADC.ATTN_11DB)
vry.atten(ADC.ATTN_11DB)
vrx.width(ADC.WIDTH_12BIT)
vry.width(ADC.WIDTH_12BIT)
# Bucle principal
while True:
valorx = vrx.read() # Leer el valor de la resistencia en X
valory = vry.read() # Leer el valor del switch/pulsador
# Encender el LED amarillo cuando valorx es 0
if valorx == 0:
encender_led_rgb(0, 0, 0, 1) # Amarillo encendido
# Encender el LED rojo y verde cuando valorsw es 2047
elif valory == 4095:
encender_led_rgb(1, 1, 0, 0) # Rojo y verde encendidos
# Encender el LED azul cuando valorx es 4095
elif valory == 0:
encender_led_rgb(1, 1, 1, 1) # Rojo y verde encendidos
# Encender el LED azul cuando valorx es 4095
elif valorx == 4095:
encender_led_rgb(0, 0, 1, 0) # Azul encendido
else:
encender_led_rgb(0, 0, 0, 0)
time.sleep_ms(50)
print(valorx)
print(valory)
print(valorsw)