Badger2040 timer visualization

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:

  1. 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?
  2. 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 :)

UPDATE… been fiddling about and it’s probably not the pythonian way but I got it to work :)

  • I’ve adapted a function I found to calculate the length of a bar, given a certain activity time. So for instance an activity is 15 mins, the function calculates that 1 bar out of 6 bars total is 150 secs.

  • Added a couple of IF statements to the WHILE loop which divides it into 6 sections, redirecting to 6 separate drawing functions (so one for each bar graphically). Each IF statements calculates 1/6th of the elapsed time based on the length of one bar and calls the function that matches. So if 2/6th of the time has passed, it calls the 4bars function

  • Each of the 6 drawing functions basically draws the number of filled bars for time left and outlined bars for time spent. Each function starts with a state check to see if it has been called before, if so, it’ll skip the screen refresh. This way the screen will only refresh 6 times regardless of the activity time.

  • Oh … also changed the 6 bars to slices of a pie … visually way more attractive :)

Added the length of each slice in the bottomleft corner and during each countdown, the white LED is blinking every second so you know it is actually doing something.

im-1

To keep with the Pimoroni examples, I’ve added a timer.txt file where 6 activities can be put including their duration. Next is to add a couple of fields for each activity so I can add specific ‘motivational’ messages to appear next to each slide on refresh.