Home Technology Development BBC micro:bit — First Steps (Part 2)

BBC micro:bit — First Steps (Part 2)


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.

JavaScript Blocks Editor for Random Numbers and Temperature
The random number and temperature program shown in the video

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.

Available at: Amazon.co.uk | Amazon.com

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.

JavaScript Blocks Editor for Random Numbers and Temperature Improved
Improved version which only does one thing at a time, and has a different animation

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.

Purchase Links

BBC micro:bit go (with accessories):
Amazon.co.uk or Amazon.com

BBC micro:bit (without accessories):
Amazon.co.uk or Amazon.com

(Using these links won’t affect the purchase price, but helps support this site. More details.)

Related Articles

Showing happy and sad face images:
BBC micro:bit – First Steps (Part 1)

Remembering the BBC Micro
Memorable 1980s Home and Personal Computers

External Links

BBC micro:bit Wikipedia Page
BBC Make It Digital

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:

Share this page