-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsequence_simple_servo.py
More file actions
40 lines (32 loc) · 1.13 KB
/
Copy pathsequence_simple_servo.py
File metadata and controls
40 lines (32 loc) · 1.13 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
# examples/basic/sequence_simple_servo.py
#
# Demonstrates: running a sequence of servo moves using sequence()
# API style: call sequence() on every loop iteration
# Async equivalent: examples/async/sequence_simple_servo.py
# Easing reference: https://philvanallen.com/easings_cheatsheet/
#
# The optional fifth element in each tuple is delay_start — seconds to wait
# before starting that move.
import board
import pwmio
from adafruit_motor import servo
from varspeed import Vspeed
MIN = 0
MAX = 180
pwm = pwmio.PWMOut(board.D13, duty_cycle=2**15, frequency=50)
my_servo = servo.Servo(pwm)
my_servo.angle = MIN
vs = Vspeed(init_position=MIN, result="int", debug=False)
vs.set_bounds(lower_bound=MIN, upper_bound=MAX)
my_sequence = [
(MAX, 2.0, 100, "QuadEaseIn"),
(MIN, 2.0, 100, "QuadEaseOut", 3), # wait 3 seconds before starting
(MAX, 2.0, 100, "SineEaseInOut", 2), # wait 2 seconds before starting
]
print("running sequence...")
running = True
while running:
position, running, changed = vs.sequence(my_sequence, loop_max=1)
if changed:
my_servo.angle = position
print("done, now at " + str(vs.position))