Random Numbers and Temperature
After getting a BBC micro:bit at Christmas, and displaying some simple images to prove it can be programmed, I wanted to make it do something a little bit more useful.
I tend to learn about new things if I’ve got a real application in mind, or a problem to solve. Things can quickly become complicated, so rather than getting carried away by trying to control my central heating system using the micro:bit, I decided to keep it simple, and make a random number generator, to help when playing board games at Christmas. Later, I added the option to display the temperature.
In the video, I’ve tried to show a reasonably straightforward version of what I did in December. Here is a screen-shot of the program.
Room for Improvement
It does a reasonable job, but it’s not perfect. One problem is that when the buttons are pressed rapidly, the screen gets messed up. That’s because the micro:bit is still in the middle of displaying one thing, when it’s asked to display another.
The version shown below fixes the problem of the display getting messed up. The button requests are stored in a variable called ‘event’, so the micro:bit will only do one thing at a time. This version also has a different doAnimation function, which shows a spinning bar — but you could use the previous one instead if you prefer.
Another problem is that there is a delay between the temperature value appearing, and the degree symbol appearing. The most effective fix I found was to display everything as text — including the degree symbol — rather than using a mixture of text and images. That involved writing some C++ using the mbed website, which redefines the font to include the degree symbol. I may post that in another article at some point.
This article has still only scratched the surface of what the micro:bit is capable of doing. With things like digital inputs and outputs, motion sensors and Bluetooth, there is still plenty more to look at. I hope that you’ll get a micro:bit, and try modifying some of my programs, as well as experimenting with your own ideas.
Showing happy and sad face images:
BBC micro:bit – First Steps (Part 1)
The website used in this article and video:
Even more ways to create code can be found at:
If you know C++, you can use mbed:
(Disclosure: Using Amazon links found here helps support this site.)