forked from FAR-Lab/Interactive-Lab-Hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
servo_test.py
28 lines (23 loc) · 893 Bytes
/
servo_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import time
from adafruit_servokit import ServoKit
# Set channels to the number of servo channels on your kit.
# There are 16 channels on the PCA9685 chip.
kit = ServoKit(channels=16)
# Name and set up the servo according to the channel you are using.
servo = kit.servo[2]
# Set the pulse width range of your servo for PWM control of rotating 0-180 degree (min_pulse, max_pulse)
# Each servo might be different, you can normally find this information in the servo datasheet
servo.set_pulse_width_range(500, 2500)
while True:
try:
# Set the servo to 180 degree position
servo.angle = 180
time.sleep(2)
# Set the servo to 0 degree position
servo.angle = 0
time.sleep(2)
except KeyboardInterrupt:
# Once interrupted, set the servo back to 0 degree position
servo.angle = 0
time.sleep(0.5)
break