Skip to content

Commit

Permalink
python: update random timer experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed May 24, 2024
1 parent f626eaf commit bcf470b
Showing 1 changed file with 59 additions and 13 deletions.
72 changes: 59 additions & 13 deletions python/src/random-timer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Imports go at the top

import random

import music
from microbit import *


Expand Down Expand Up @@ -37,22 +39,66 @@ class MyImages:
"90609:"
) # fmt: off

hourglass_progress_2: Image = Image(
"99999:"
"09990:"
"00900:"
"09690:"
"99999:"
) # fmt: off

hourglass_progress_3: Image = Image(
"99999:"
"09990:"
"00900:"
"09090:"
"99999:"
) # fmt: off

myimages = MyImages()

print("INFO: Random Hourglass Timer")
class RandomTimer:
"""Random Timer experiment"""

# Code in a 'while True:' loop repeats forever
while True:
seconds: int = random.randint(10, 90)
display.show(myimages.hourglass_start)
sleep(1_000)
def __init__(self) -> None:
self.images: MyImages = MyImages()
self.lower_bound: int = 10
self.upper_bound: int = 90
self.duration: int = 0

print("INFO: starting " + str(seconds) + " second timer")
for i in range(0, seconds):
display.show(getattr(myimages, "hourglass_progress_" + str(i % 2)))
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: timer has completed")
display.show(myimages.hourglass_end)
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)

0 comments on commit bcf470b

Please sign in to comment.