Last active
January 30, 2023 21:17
-
-
Save gigafide/3f49d656d4662cd02a2808bc0c4a1c95 to your computer and use it in GitHub Desktop.
Raspberry Pi Pico servo and potentiometer control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin, PWM, ADC | |
from time import sleep | |
pot = ADC(Pin(28)) | |
servo = PWM(Pin(0)) | |
servo.freq(50) | |
def move_servo(degrees): | |
if degrees > 180: | |
degrees = 180 | |
if degrees < 0: | |
degrees = 0 | |
MAX = 9000 | |
MIN = 1000 | |
newValue = MIN+(MAX-MIN)*(degrees/180) | |
servo.duty_u16(int(newValue)) | |
while True: | |
value = pot.read_u16() | |
print(value) | |
degree=value*180/65500 | |
move_servo(degree) | |
sleep(0.01) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment