from machine import Pin,PWM,ADC
def map_values(val):
return int(((val/4095) * (122-25)) + 25)
def calc_angle(val):
return int(((servo_val-25) / (122-25)) * 180)
# initialize the servo motor
servo = PWM(Pin(23,mode=Pin.OUT))
servo.freq(50)
# initialize the ADC (Potentiometer)
adc = ADC(Pin(32))
adc.atten(ADC.ATTN_11DB)
while True:
val = adc.read()
servo_val = map_values(val)
servo.duty(servo_val)
angle = calc_angle(servo_val)
print(f'ADC Value: {val} \t|\t Servo Value: {servo_val} \t|\t Angle: {angle}[deg]')