-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetExercise.py
50 lines (45 loc) · 1.55 KB
/
getExercise.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
# Sensehat script
# Allows a user to select exercise type
# Ian Mullins
from sense_hat import SenseHat
green = (0, 255, 0)
scroll = 0.05
def getExercise():
try:
sense = SenseHat()
str = "Select workout.."
print(str)
sense.show_message(str, scroll_speed=scroll)
option = None
if option is not None:
del option
# Wait for user exercise selection via sensehat joystick
# Joystick left = Deadlift
# Joystick right = Squat
# Joystick up = Bench Press
while True:
for event in sense.stick.get_events():
if event.direction == "left":
option = "Deadlifts"
sense.show_message(
option, text_colour=green, scroll_speed=scroll)
sense.clear()
return option
elif event.direction == "right":
option = "Squats"
sense.show_message(
option, text_colour=green, scroll_speed=scroll)
sense.clear()
return option
elif event.direction == "up":
option = "Bench-press"
sense.show_message(
option, text_colour=green, scroll_speed=scroll)
sense.clear()
return option
except Exception as e:
print("Oops!", e.__class__, "occurred.")
if __name__ == "__main__":
option = getExercise()
print(option)
sense.clear()