import board
import analogio
import pwmio
import time
# Set up the potentiometer on GP26 as an analog input
pot = analogio.AnalogIn(board.GP26)
# Set up the LED on GP15 as a PWM output (Pulse Width Modulation)
led = pwmio.PWMOut(board.GP15, frequency=5000, duty_cycle=0)
def get_voltage(pin):
#Convert the analog value (0-65535) to a voltage (0-3.3V)
return (pin.value * 3.3) / 65535
while True:
# Read the potentiometer value (0-65535)
pot_value = pot.value
# Convert the potentiometer value to a voltage (0-3.3V)
voltage = get_voltage(pot)
# Map potentiometer value (0-65535) to a PWM duty cycle (0-65535)
led.duty_cycle = pot_value
# Print the potentiometer value and LED brightness for debugging
print(f"Potentiometer Value: {pot_value}, Voltage: {voltage:.2f}V, LED Brightness: {led.duty_cycle}")
# Small delay for readability and stability
time.sleep(0.1)