from machine import Pin, ADC, PWM
from time import sleep
# Define pins
led_pin = 2
pot_pin = 34
# Initialize LED pin as PWM
led = PWM(Pin(led_pin), freq=5000)
# Initialize potentiometer pin as ADC
pot = ADC(Pin(pot_pin))
pot.atten(ADC.ATTN_11DB) # Configure the attenuation for full range (0-3.3V)
while True:
pot_value = pot.read() # Read the value from the potentiometer
pwm_value = int(pot_value / 4095 * 1023) # Map the potentiometer value to the PWM range (0-1023)
led.duty(pwm_value) # Set the PWM duty cycle to control brightness
print("Potentiometer Value:", pot_value, "- PWM Value:", pwm_value)
sleep(0.1) # Small delay for stability