-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacc.py
44 lines (35 loc) · 945 Bytes
/
acc.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
from sense_hat import SenseHat
sense = SenseHat()
sense.clear()
o = sense.get_orientation()
pitch = o["pitch"]
roll = o["roll"]
yaw = o["yaw"]
print("pitch {0} roll {1} yaw {2}".format(pitch, roll, yaw))
acceleration = sense.get_accelerometer_raw()
x = acceleration['x']
y = acceleration['y']
z = acceleration['z']
x=round(x, 0)
y=round(y, 0)
z=round(z, 0)
print("x={0}, y={1}, z={2}".format(x, y, z))
sense.show_letter("J")
while True:
acceleration = sense.get_accelerometer_raw()
x = acceleration['x']
y = acceleration['y']
z = acceleration['z']
x=round(x, 0)
y=round(y, 0)
z=round(z, 0)
print("x={0}, y={1}, z={2}".format(x, y, z))
# Update the rotation of the display depending on which way up the Sense HAT is
if x == -1:
sense.set_rotation(90)
elif y == 1:
sense.set_rotation(0)
elif y == -1:
sense.set_rotation(180)
else:
sense.set_rotation(270)