Files
hpr-knowledge-base/hpr_transcripts/hpr4075.txt

173 lines
14 KiB
Plaintext
Raw Normal View History

Episode: 4075
Title: HPR4075: Making a Pomodoro Timer
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr4075/hpr4075.mp3
Transcribed: 2025-10-25 19:17:49
---
This is Hacker Public Radio episode 4,075 for Friday the 15th of March 2024.
Today's show is entitled Making a Pomodoro Timer.
It is hosted by Norrist, and is about 20 minutes long.
It carries a clean flag.
The summary is Norrist uses the Pomodoro method to keep from getting fired.
Hello Hacker's.
I'm going to talk about making a Pomodoro Timer out of a circuit python express.
Talk about what it is and why I made it.
So I get distracted really easily when I'm supposed to be working in that was really
only made worse when a few years ago I started working at home.
That's been one of my biggest challenges with working from home is trying to manage
distractions.
So what will happen is if I'm trying to work on just kind of a single work dictated
task after 20-30 minutes of being sort of focused on one thing, my mind just starts drifting
and I start looking for anything just anything else that I can do or get distracted by.
So in order to keep my productivity up to a standard that is satisfactory for my employer,
I have to look for ways to make myself stay on task and it's kind of forcing myself
through it.
It works but it's not fun and I can stay on task but I don't really do great work.
So I decided that instead of fighting my natural urge to only work for 20 or 30 minutes
to sort of embrace it.
So instead of treating it as a limitation, use that and sort of build a method of working
around that and force myself to take short breaks.
So work for your period and take a short break for a period.
So the method I decided to try is called the Pomodoro method.
I have a link to the Wikipedia article about it but it sort of was a quick summary.
It was developed in the 80s by a developer named Francesco Cerrillo and he used a kitchen
timer to do it which is a really good way, honestly, to do it.
But it's just like I described, you work for an interval typically 25 or so minutes and
then you take short breaks.
Some people use it because it helps them work better and mostly I use it because it
helps them work better but also I can stay on task easier if I know there's a break
coming up.
So it improves my quality of work but also my mind can stay focused if I know in a finite
amount of time I'll let myself do something else.
So when I started kind of digging in and how I wanted to do the Pomodoro technique
and I've tried it a few times before, the hard thing about it is sticking to it.
So there's plenty of apps regardless of what kind of phone you have or desktop apps or
phone apps.
There's a lot of things out there and you can just use any timer or just fine.
But like I said, it's the hard part about it is the discipline it's to use it.
I wanted something on my desk that I could look at and it would actually kind of get my
attention and remind me that I was supposed to be doing this thing.
So I decided to make myself a timer using the circuit playground express.
So my, I don't know if it was my last episode or maybe two episodes ago I talked about using
a Raspberry Pi Pico to type some passwords for me kind of using the Pi Pico as a password
manager for websites that don't let you copy and paste.
And I mentioned that my first attempt at doing that was using this playground express and
I wanted to switch to a Pi because I wanted to do something else with the playground express
and the Pomodoro timer was something else that I wanted to use it for.
So just a quick refresher if you didn't listen to it or if you forgot the playground express
is a microcontroller it's made by the Adafruit company it's kind of a unique circular shape
you know instead of a rectangle or square like a lot of microcontrollers it's a circle
around the circle there's LEDs and then kind of in the middle it's kind of a whole bunch
of input devices it's got a switch and a couple of buttons and it can do temperature sensing
but like I said the main reason I wanted to use it is because it has 10 LEDs in a circle
and they're multicolor LEDs you can program that you can program the LEDs and which ones
are on or off and what color they'll be and it runs circuit to Python which has a ton
of libraries including libraries that make it really easy to use the pixels called neopixels
the neopixels on the circuit playground express. So the other thing I wanted to do while I was
working on this is about once a year or so I'll get a bug in my brain to try test driven
development again and I've done a few times I like doing it it's been official if you're
not in a crazy rush and it does slow if you you know overall if you're doing a giant project
I don't think test driven development will slow you down but if you're doing something you know
that's super quick that you can do in an hour test driven development probably may not be the
right thing to do if you're if you're you know totally focused on it's sort of a quick primer on
what test driven development is it's before you write any actual code to do you know what you're
want to do you write a test and you so you write a test you run the test it should fail
and then you write the simplest code that will get that test to pass and then once you're certain
that the test is passing and you can go back and refactor the code to make it better and then
while you're doing it while you're making it better you can keep running the test and make sure
the test continue to pass then when you when you get that done you you move on so you ride a
little chunk of code well you ride a test then you ride a little chunk of code that satisfies the
test you can fix the code up once once you got it done then you move on to the next piece so a few
advantages reasons that I like to do test driven development is it it kind of forces you to
write your code in small functions and that makes that always makes it easier when you come back
to the projects later and there's either something you need to change or you forgot how it works
if you can look at anytime you can look at small discrete sections of code at least for me I'll say
you but at least for me whenever I can look at small sections it's easier for me to put together
what the actual code what the code is doing it's harder to get lost in code that's in a small
separate chunks one little piece does one thing another advantage is that if you decide that you've
got a small section that needs to be rewritten or there's something you want to do or a buggy
fix it's easier to rewrite if you if you when it's chunked up your code is divided up into
discrete sections you won't if there's something you've got to fix you've only got to fix that
one little section so it makes it easier to test and it gives you confidence whenever you
are making changes to the code you know the whole time you're making changes you're running
your test suite and if you've got you know kind of a what's in your head as a major rewrite to do
or let's say you you know there's a function that you totally want to change how that function works
you know that if you wrote good tests it doesn't matter if you completely start from scratch and
start over and write this bit of code totally differently as long as the test pass you know the
application overall will work okay so I said I mentioned that it's going to be writing the code
for the pulmonary rotimer and circuit python in the way circuit python works is that you put a file
when you plug the board in the single board computer in it pops up like it's a usb thumb
drive and then you put a file on there on the circuit or on the micro controller called code
code.py and whenever the micro controller boots that's what it executes it looks for a file called
code.py and runs that file so a lot of the code that you write for a micro controller will only run
on that micro controller and what what I mean by that is if you've got code to turn an LED on
or LED off or check a temperature sensor or something like that that code is not going to work
on your laptop because your laptop doesn't have those hardware devices so what I wanted to do
when I was writing this is I wanted to put the smallest amount of code possible in code.py
and then write kind of a separate library that I could test on my laptop so I took
as much code as I could and put it in a separate file called palmadoro.py and then when I was writing
the code and testing the code I could do all that work on a laptop just kind of separate. This
way I didn't have to do I could develop without the sbc I could write some code test the code
without having to have the sbc right there. So if you look at code.py some stuff that we'll have
in there and links in the show notes by the way all this stuff is checked in to get out but I'll
definitely have this stuff in the show notes but in code.py like I said it's got the functions that
require the hardware to be there to run so the stuff in code.py I didn't necessarily write
test for but you know just some things that are actually in there's one there's a bunch of there's
some variables and constants to find at the top of the file including the break break minutes
and work minutes so remember the palmadoro technique you work for a period and take a break for
a period so you can set you can set those values I mentioned in the Wikipedia article it says 25
minutes and five minutes I've actually found that after I'm working for about 20 minutes I start
glancing around and trying to figure out how much time is left so I figured I may as well just
I just set my timer to 20 minutes because after after I'm working for 20 minutes if I'm
or if my brain is kind of clicking around looking for a break I may as well it's best just
stop then so I set my work period for 20 minutes break period for five minutes
and then also in the code.py this is where the code that's tracking the time
you know how long has it been since you started a work period or a break period
and then the way it knows how many LEDs to light up is it'll just take the how many minutes has
it has it been and then divide that by the number of LEDs and then that will give you how many
LEDs should be turned on then I'll talk in a second about how the timer actually works
so I was pretty impressed with the circuit python and the single board computers that they could
even keep up with time now they don't do time like our computer does you know they don't have a
battery in a clock or ntp or anything like that but they can they can count you know they do know
how much time has passed so when I coding counting time on the microcontrollers is a little bit
different than but it works and it's it's not too hard and you can see examples of how I do it
but a little bit about how the actual timer works and how how I use it
so like I said it's got circuit python express it's got 10 LEDs and two buttons that's primarily
what I'm using while I'm working or while it's counting down a work period I'll use I'll turn
all their LEDs white and then there'll be a green LED for every sort of work segment that I've
been doing so you know if I if I've got it set for 20 minutes and you know there's 10 LEDs
then every two minutes another LED will come on so it'll you know one you know be all white
with one green and then two green and three greens and if it's counting down correctly by the time it
gets to all the greens lit that's that's the end of your work period and then for bright time I do
something similar except I use blue instead of green so it'll you know I'm gonna start a break
we'll just you know turn all the LEDs white and then as the work as the break period progresses
it'll turn more and more LEDs blue like I said there's two buttons on the circuit playground express
so I've got one button you press and it starts a work period and the other button you press and it
will start a break period and when you when the periods are finished when the work period is finished
and the break period is finished I wanted it to get my attention in case I'm distracted
so it will it will blink a few times to let me know that a period has just finished
and then while it's idle instead of if it's not counting down actively counting down a work period
or a break period what I'll do is I'll turn all the LEDs off and the then the except for
the LED that's closest to the button to start work that will be lit green to remind me that
you know if I want to start work I'll press that button and the same for the button to start a
break period it will be the LED that's closest to that button will be lit blue and then anytime while
it's running if you're in the middle of a break period and you want to start work you can just
press the button it'll detect that and kind of abandon the break period and start a work period
so I'll have a few links at the bottom of the show notes I'll link to my get lab page where I'm
got this code written only to the circuit playground or circuit python page there was another
episode recently about circuit python and my answering computer lab temperatures I thought that
was very interesting if this is something you are even remotely interested in single board
computers and or python I'd encourage you to take a look I said it in the last episode I did
about passwords these raspberry poppecos are a whopping $4 so it doesn't take a lot of investment to
get started and you don't if you just want a blinking LED that's all you need if you want to you know
some microcontroller projects you might have to get headers and breadboards and stuff like that
but you can definitely get started with circuit python and raspberry poppeco so I think that's it
until I've got to talk about I hope you guys are excited about circuit python and microcontrollers
and I look forward to some feedback on the episode and I will see you guys next time
you have been listening to hacker public radio at hacker public radio does work today show was
contributed by a hbrlisnet like yourself if you ever thought of recording podcast and click on
our contribute link to find out how easy it leads hosting for hbr has been kindly provided by
monstros.com the internet archive and our sims.net unless otherwise stated today's show is released
under a creative commons attribution 4.0 international license