29 lines
681 B
Python
29 lines
681 B
Python
# SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries
|
|
#
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
"""CircuitPython Essentials Servo continuous rotation servo example"""
|
|
import time
|
|
import board
|
|
import pwmio
|
|
from adafruit_motor import servo
|
|
|
|
# create a PWMOut object on Pin A2.
|
|
pwm = pwmio.PWMOut(board.A2, frequency=50)
|
|
|
|
# Create a servo object, my_servo.
|
|
my_servo = servo.ContinuousServo(pwm)
|
|
|
|
while True:
|
|
print("forward")
|
|
my_servo.throttle = 1.0
|
|
time.sleep(2.0)
|
|
print("stop")
|
|
my_servo.throttle = 0.0
|
|
time.sleep(2.0)
|
|
print("reverse")
|
|
my_servo.throttle = -1.0
|
|
time.sleep(2.0)
|
|
print("stop")
|
|
my_servo.throttle = 0.0
|
|
time.sleep(4.0)
|