-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom-timer.py
104 lines (77 loc) · 1.97 KB
/
random-timer.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Imports go at the top
import random
import music
from microbit import *
class MyImages:
hourglass_start: Image = Image(
"99999:"
"09990:"
"00900:"
"09090:"
"90009:"
) # fmt: off
hourglass_end: Image = Image(
"90009:"
"09090:"
"00900:"
"09990:"
"99999:"
) # fmt: off
hourglass_progress_0: Image = Image(
"99999:"
"09990:"
"00900:"
"09690:"
"90009:"
) # fmt: off
hourglass_progress_1: Image = Image(
"99999:"
"09990:"
"00900:"
"09090:"
"90609:"
) # fmt: off
hourglass_progress_2: Image = Image(
"90009:"
"09990:"
"00900:"
"09690:"
"99999:"
) # fmt: off
hourglass_progress_3: Image = Image(
"90009:"
"09990:"
"00900:"
"09090:"
"99999:"
) # fmt: off
class RandomTimer:
"""Random Timer experiment"""
def __init__(self) -> None:
self.images: MyImages = MyImages()
self.lower_bound: int = 10
self.upper_bound: int = 90
self.duration: int = 0
def run(self) -> None:
"""Run the timer."""
self.duration: int = random.randint(self.lower_bound, self.upper_bound)
display.show(self.images.hourglass_start)
sleep(1_000)
print("INFO: starting " + str(self.duration) + " second timer")
offset: int = 0
for i in range(self.duration, 0, -1):
if i < self.duration // 2:
offset = 2
display.show(getattr(self.images, "hourglass_progress_" + str(offset + (i % 2))))
sleep(1_000)
print("INFO: timer has completed")
display.show(self.images.hourglass_end)
music.play(music.BA_DING)
print()
print("Random Timer")
print()
app: RandomTimer = RandomTimer()
# Code in a 'while True:' loop repeats forever
while True:
app.run()
sleep(5_000)