-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmove_simple_servo.py
More file actions
executable file
·42 lines (34 loc) · 1.13 KB
/
Copy pathmove_simple_servo.py
File metadata and controls
executable file
·42 lines (34 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
41
42
# examples/basic/move_simple_servo.py
#
# Demonstrates: moving a servo using move()
# API style: call move() on every loop iteration
# Async equivalent: examples/async/move_simple_servo.py
# Easing reference: https://philvanallen.com/easings_cheatsheet/
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)
print("moving to " + str(MAX) + "...")
running = True
while running:
position, running, changed = vs.move(
new_position=MAX, time_secs=2, steps=180, easing="ExponentialEaseInOut", delay_start=3.0
)
if changed:
my_servo.angle = position
print("moving to " + str(MIN) + "...")
running = True
while running:
position, running, changed = vs.move(
new_position=MIN, time_secs=2, steps=180, easing="ExponentialEaseInOut", delay_start=3.0
)
if changed:
my_servo.angle = position
print("done, now at " + str(vs.position))