-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathup-arrow.py
66 lines (59 loc) · 1.57 KB
/
up-arrow.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
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
59
60
61
62
63
64
65
66
from sense_hat import SenseHat
from time import sleep
import random
sense = SenseHat()
RD = [255, 0, 0]
BK = [0, 0, 0]
STRAIGHT_ARROW = [
BK, BK, BK, RD, RD, BK, BK, BK,
BK, BK, RD, RD, RD, RD, BK, BK,
BK, RD, BK, RD, RD, BK, RD, BK,
BK, BK, BK, RD, RD, BK, BK, BK,
BK, BK, BK, RD, RD, BK, BK, BK,
BK, BK, BK, RD, RD, BK, BK, BK,
BK, BK, BK, RD, RD, BK, BK, BK,
BK, BK, BK, RD, RD, BK, BK, BK
]
DIAGONAL_ARROW = [
BK, BK, BK, BK, RD, RD, RD, RD,
BK, BK, BK, BK, BK, RD, RD, RD,
BK, BK, BK, BK, RD, RD, RD, RD,
BK, BK, BK, RD, RD, RD, BK, RD,
BK, BK, RD, RD, RD, BK, BK, BK,
BK, RD, RD, RD, BK, BK, BK, BK,
RD, RD, RD, BK, BK, BK, BK, BK,
BK, RD, BK, BK, BK, BK, BK, BK
]
def set_rotation_angle(yaw_degrees):
if 25 <= yaw_degrees < 65:
arrow = DIAGONAL_ARROW
angle = 0
elif 65 <= yaw_degrees < 115:
arrow = STRAIGHT_ARROW
angle = 0
elif 115 <= yaw_degrees < 155:
arrow = DIAGONAL_ARROW
angle = 270
elif 155 <= yaw_degrees < 205:
arrow = STRAIGHT_ARROW
angle = 270
elif 205 <= yaw_degrees < 245:
arrow = DIAGONAL_ARROW
angle = 180
elif 245 <= yaw_degrees < 295:
arrow = STRAIGHT_ARROW
angle = 180
elif 295 <= yaw_degrees < 335:
arrow = DIAGONAL_ARROW
angle = 90
else:
arrow = STRAIGHT_ARROW
angle = 90
return arrow, angle
while True:
orientation = sense.get_orientation_degrees()
yaw = round(orientation['yaw'])
arrow, angle = set_rotation_angle(yaw)
sense.set_rotation(angle)
sense.set_pixels(arrow)
sleep(0.2)