from machine import Pin, ADC, PWM
from time import sleep
# Set up PWM for LEDs
red_led = PWM(Pin(2), freq=5000)
green_led = PWM(Pin(4), freq=5000)
blue_led = PWM(Pin(5), freq=5000)
# Set up ADC for potentiometers
pot1 = ADC(Pin(34)) # GPIO34
pot2 = ADC(Pin(35)) # GPIO35
pot3 = ADC(Pin(33)) # GPIO33
# Configure ADC attenuation
pot1.atten(ADC.ATTN_11DB) # Full-scale voltage is 3.3V
pot2.atten(ADC.ATTN_11DB) # Full-scale voltage is 3.3V
pot3.atten(ADC.ATTN_11DB) # Full-scale voltage is 3.3V
while True:
# Read ADC values
pot1_value = pot1.read()
pot2_value = pot2.read()
pot3_value = pot3.read()
# Map ADC values (0-4095) to PWM duty cycle (0-1023)
red_duty = int(pot1_value / 4095 * 1023)
green_duty = int(pot2_value / 4095 * 1023)
blue_duty = int(pot3_value / 4095 * 1023)
# Set PWM duty cycle for LEDs
red_led.duty(red_duty)
green_led.duty(green_duty)
blue_led.duty(blue_duty)
# Wait for a short period
sleep(0.1)