Close

Productivity Meets Urology

A project log for VoiceBox

Adding a Flask web interface (and other stuff) to the Google AIY Voice Kit.

tmTM 08/16/2018 at 23:220 Comments

Way back in 2014 I saw a piece about a Pomodoro Timer on the Hackaday blog and I've been meaning to build one ever since. (A timer that shows 5 red LEDs each representing 5 minutes of work; after 25 minutes they're replaced by 5 green LEDs, each representing 1 minute of rest.)

Unfortunately, in the 4+ years since, I've never been able to focus for the 25 minutes needed to get a good start on a hardware Pomodoro timer project. But now I have VoiceBox, complete with a Blinkt strip of RGB LEDs on my desk, so I finally got around to implementing one.

The main meat is the addition of a new pattern, 'pomodoro', to the Blinkter server:

# ************* POMODORO *************
POMODORO_INTERVAL = 30.0
POMODORO_WORK     = 25.0
POMODORO_REST     = POMODORO_INTERVAL - POMODORO_WORK
POMODORO_LEDS     = 5
WORK_MINS_PER_LED = POMODORO_WORK / POMODORO_LEDS
REST_MINS_PER_LED = POMODORO_REST / POMODORO_LEDS
POMODORO_SLEEP    = 0.2
POMODORO_SOUND    = '/home/pi/Python/Blinkter/static/sounds/small_bell.wav'
def pomodoro(pomodoro_start_time):
    global paused, paused_time
    
    start_processing_time = time.time()
    minutes = ((time.time() - pomodoro_start_time) / 60.0) % POMODORO_INTERVAL # minutes elapsed this cycle
    blinkt.clear()
    if minutes < POMODORO_WORK:
        work = POMODORO_WORK - minutes         # minutes of work remaining
        for i in range(0, 5):
            residue = work - i*WORK_MINS_PER_LED
            if residue > 0:
                brightness = 1.0 if residue > WORK_MINS_PER_LED else residue / WORK_MINS_PER_LED
                setRGB(i, RED, brightness * (0.25 if paused else 1.0))
        if work*60.0 <= POMODORO_SLEEP:
            subprocess.Popen(['aplay', POMODORO_SOUND])
    else:
        rest = POMODORO_INTERVAL - minutes     # minutes of rest remaining
        for i in range(0, 5):
            residue = rest - i*REST_MINS_PER_LED
            if residue > 0:
                brightness = 1.0 if residue > REST_MINS_PER_LED else residue / REST_MINS_PER_LED
                setRGB(7-i, GREEN, brightness * (0.25 if paused else 1.0))
        if rest*60.0 <= POMODORO_SLEEP:
            subprocess.Popen(['aplay', POMODORO_SOUND])
        
    blinkt.show()
    time.sleep(POMODORO_SLEEP)
    
    if paused: paused_time += time.time() - start_processing_time # shift the pomodoro start time if paused

I also modified the Blinkter pattern page to display a pause/restart button while the 'pomodoro' timer is running.

So now I have no excuse not to be focused and productive. 

P.S. Why "urology"? In the absence of a timer, I used to alternate between coffee breaks and bathroom breaks. The Pomodoro timer should be much better for my plumbing. 

Discussions