User Manual

For the Metro M4 Express, ItsyBitsy M4 Express and
the Feather M4 Express, connect the ground wire to
any G or GND, the power wire to USB or 5V, and the
signal wire to A1.
Standard Servo Code
Here's an example that will sweep a servo connected to pin A2 from 0 degrees to 180 degrees (-90 to 90 degrees)
and back:
Continuous Servo Code
There are two differences with Continuous Servos vs. Standard Servos:
1. The servo object is created like my_servo = servo.ContinuousServo(pwm) instead of my_servo =
servo.Servo(pwm)
2. Instead of using myservo.angle , you use my_servo.throttle using a throttle value from 1.0 (full on) to 0.0
(stopped) to -1.0 (full reverse). Any number between would be a partial speed forward (positive) or reverse
(negative). This is very similar to standard DC motor control with the adafruit_motor library.
This example runs full forward for 2 seconds, stops for 2 seconds, runs full reverse for 2 seconds, then stops for 4
seconds.
import time
import board
import pulseio
from adafruit_motor import servo
# create a PWMOut object on Pin A2.
pwm = pulseio.PWMOut(board.A2, 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)
© Adafruit Industries https://learn.adafruit.com/adafruit-metro-m4-express-airlift-wifi Page 126 of 187