from machine import Pin, PWM, ADC
import utime
# Potentiometer and Servo Motor Configuration
pot = ADC(Pin(28)) # Potentiometer pin
servo = PWM(Pin(20)) # Servo motor pin
servo.freq(50) # Servo operating frequency
# Conversion Constants
CONVERSION_FACTOR = 0.10681
MIN_PULSE_WIDTH = 2000
# Main Loop
while True:
pot_value = pot.read_u16() # Read potentiometer value (0 to 65535)
angle = round(pot_value * CONVERSION_FACTOR + MIN_PULSE_WIDTH) # Convert to servo angle
servo.duty_u16(angle) # Control the servo motor
print("Potentiometer Value: {} | Servo Angle: {}".format(pot_value, angle)) # Display in console
utime.sleep(0.05) # Small delay