I’ve created a working countdown timer which has preset activities. You can select an activity from a menu and start the countdown. For instance “put on shoes” starts a 5 mins countdown, “shower” is a 20 mins countdown.
The countdown is refreshing the e-INK screen every second while it counts down. It works great.
Unfortunately, it’s not so good for the lifetime of the screen. I’d like to visualize the countdown with 6-bars that disappear and only show the minutes remaining instead of minutes and seconds. Screen refresh will be 6 times instead of 1200 times for a 20 mins shower.
I’ve been trying to get this to work for a couple of days but run into two problems:
- how to keep the countdown function counting down every second but refreshing the screen only 6 times for each bar that needs to disappear. Do I keep my existing countdown function and create a separate bars_update function ? Or do I make one function for it all?
- how to create a function that divides the time in 6 equal parts for the bars. 3 bars down = half-way regardless of preset duration.
12 minutes preset duration: half-way = 6 mins = 3 bars visible,
5 minutes preset duration: half-way = 2.5 mins = 3 bars visible
My current countdown function:
def countdown(time_sec):
display.update_speed(badger2040.UPDATE_TURBO)
while time_sec:
mins, secs = divmod(time_sec, 60)
timeformat = '{:02d}:{:02d}'.format(mins,secs)
print(timeformat, end='\r')
time.sleep(1)
time_sec -= 1
display.pen(15)
display.rectangle(100, 45, 100, 30)
display.pen(0)
display.thickness(2)
display.text(timeformat, 100, 60, TIME_TEXT_SIZE)
display.update()
print("stoppppp")
display.pen(0)
display.rectangle(100, 45, 100, 30)
display.pen(15)
display.text("KLAAR", 100, 60, TIME_TEXT_SIZE)
display.update()
I appreciate any insights or suggestions or examples :)