Skip to content

Instantly share code, notes, and snippets.

@suadanwar
Created April 9, 2021 03:43
Show Gist options
  • Save suadanwar/421146c566f0c420279a985c7cb71f08 to your computer and use it in GitHub Desktop.
Save suadanwar/421146c566f0c420279a985c7cb71f08 to your computer and use it in GitHub Desktop.
This sample code is for Servo with Raspberry Pi Pico using CircuitPython
import time
import board
import pwmio
from adafruit_motor import servo
# create a PWMOut object on Pin GP27.
pwm = pwmio.PWMOut(board.GP27, duty_cycle=2 ** 15, frequency=50)
# Create a servo object, my_servo.
my_servo = servo.Servo(pwm)
while True:
for angle in range(0, 180, 5): # 0 - 180 degrees, 5 degrees at a time.
my_servo.angle = angle
time.sleep(0.05)
for angle in range(180, 0, -5): # 180 - 0 degrees, 5 degrees at a time.
my_servo.angle = angle
time.sleep(0.05)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment