forked from BenIanGifford/sense-hat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotating_letter.py
75 lines (59 loc) · 1.56 KB
/
rotating_letter.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
67
68
69
70
71
72
73
74
75
from sense_hat import SenseHat
sh = SenseHat()
#from time import sleep
# sh.show_letter("I")
# set up the colours (white, green, red, empty)
w = [150, 150, 150]
g = [0, 255, 0]
r = [255, 0, 0]
e = [0, 0, 0]
# create images for coloured arrow
arrow = [
e, e, e, w, w, e, e, e,
e, e, w, w, w, w, e, e,
e, w, e, w, w, e, w, e,
w, e, e, w, w, e, e, w,
e, e, e, w, w, e, e, e,
e, e, e, w, w, e, e, e,
e, e, e, w, w, e, e, e,
e, e, e, w, w, e, e, e
]
red_arrow = [
e,e,e,r,r,e,e,e,
e,e,r,r,r,r,e,e,
e,r,e,r,r,e,r,e,
r,e,e,r,r,e,e,r,
e,e,e,r,r,e,e,e,
e,e,e,r,r,e,e,e,
e,e,e,r,r,e,e,e,
e,e,e,r,r,e,e,e
]
# Print it once
#sh.set_pixels(arrow)
while True:
# Below works with Rasbian's Python 2.7.9
# x_full, y_full, z_full = sh.get_accelerometer_raw().values()
# Below works with Rasbian's Python 3.4.2 AND 2.7.9
raw = sh.get_accelerometer_raw()
x=round(raw['x'], 0)
y=round(raw['y'], 0)
z=round(raw['z'], 0)
# Not really needed, except for perhaps debugging
# Below works with Rasbian's Python 2.7.9
#print ("x=%s, y=%s, z=%s" % (x_full,y_full,z_full))
# Below works with Rasbian's Python 3.4.2 AND 2.7.9
#print ("x=%s, y=%s, z=%s" % (raw['x'],raw['y'],raw['z']))
if x == -1:
sh.set_pixels(arrow)
sh.set_rotation(90)
elif x == 1:
sh.set_pixels(red_arrow)
sh.set_rotation(270)
elif y == 1:
sh.set_pixels(arrow)
sh.set_rotation(0)
elif y == -1:
sh.set_pixels(red_arrow)
sh.set_rotation(180)
else:
sh.show_letter("*")