forked from pimoroni/inventorhatmini-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiple_servos.py
More file actions
58 lines (48 loc) · 1.42 KB
/
multiple_servos.py
File metadata and controls
58 lines (48 loc) · 1.42 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import time
import math
from inventorhatmini import InventorHATMini
"""
Demonstrates how to control all of the servos on Inventor HAT Mini.
"""
# Create a new InventorHATMini
board = InventorHATMini(init_leds=False)
# Enable all servos (this puts them at the middle)
for s in board.servos:
s.enable()
time.sleep(2)
# Go to min
for s in board.servos:
s.to_min()
time.sleep(2)
# Go to max
for s in board.servos:
s.to_max()
time.sleep(2)
# Go back to mid
for s in board.servos:
s.to_mid()
time.sleep(2)
SWEEPS = 3 # How many sweeps of the servo to perform
STEPS = 10 # The number of discrete sweep steps
STEPS_INTERVAL = 0.5 # The time in seconds between each step of the sequence
SWEEP_EXTENT = 70.0 # How far from zero to move the servo when sweeping
# Do a sine sweep
for j in range(SWEEPS):
for i in range(360):
value = math.sin(math.radians(i)) * SWEEP_EXTENT
for s in board.servos:
s.value(value)
time.sleep(0.02)
# Do a stepped sweep
for j in range(SWEEPS):
for i in range(0, STEPS):
for s in board.servos:
s.to_percent(i, 0, STEPS, 0.0 - SWEEP_EXTENT, SWEEP_EXTENT)
time.sleep(STEPS_INTERVAL)
for i in range(0, STEPS):
for s in board.servos:
s.to_percent(i, STEPS, 0, 0.0 - SWEEP_EXTENT, SWEEP_EXTENT)
time.sleep(STEPS_INTERVAL)
# Disable the servos
for s in board.servos:
s.disable()