micro:bit a guide

About

I have no affiliation with the BBC, Microsoft, or any of the partners involved in making the micro:bit

It also contains a variety of programs I've written for it, which may help in your classroom. All are FREE and include:

Full source code, online

A screenshot of the source

A screenshot of the program running

The .hex file, which you can download directly

The Official Blurb

The BBC has unveiled the BBC micro:bit, a pocket-sized codeable computer with motion detection, a built-in compass and Bluetooth technology, which is to be given free to every child in year 7 or equivalent across the UK.

A collaboration between 29 partners, the micro:bit is the BBC's most ambitious education initiative in 30 years, with an ambition to inspire digital creativity and develop a new generation of tech pioneers.

My Opinion

For those that don't know me, and haven't seen the rest of marquisdegeek.com,
I'm an edTech CTO and general-purpose computer geek! My career has lasted 22 years (touch wood!) and given me the
opportunity to work on more languages and platforms than I care to remember. The only important thing I need
to reminder you regarding my involvement with the micro:bit is this:

I have no affiliation with the BBC, Microsoft, or any of the partners involved in making the micro:bit

And because I have no pay masters, I can say what I like about it!

During it's development I was hopeful for the device, but my first impressions were poor. And, in many ways, they failed
to live up to even these expectations.

Kids in the target market (year 7 and above) usually have phones and computer access, where they have access to far
more impressive development environments than the 25 lights, so why should the micro:bit excite them?

The supplied cable is stupidly short. 15.5cm, to be exact. This won't reach from a desktop (or laptop) PC to anywhere
usable, and it's too short to let the compass be used effectively. Make sure you ask IT to order cables at the same time you
request your micro:bit.

There are four programming environments available: Touch Develop, Javascript, Block Editor, and Python. While I appreciate the value in choice, especially with a range of ability
levels, asking a non-technical teacher to make the most effective choice of programming language is a big ask.

The Touch Develop online environment is clumsy and inconsistent, making the simplest tasks painful. (Programming doesn't need to be this hard!)

The Touch Develop language appears incomplete. e.g. there's a way to tell the micro:bit to do stuff when a button is pressed... but
not when it is released.

The examples are little more than hand-holding exercises. There's very little in the way of creative thought, and
even less in the way of opportunities to explore. I believe this is partly due to the 'by rote' method of teaching
employed, and the (in)ability of the language and environment to foster this.

However, it's not all bad.

The program I wrote compiled, downloaded, and ran on the device the first time I tried it!

The Main Function

When the micro:bit is switched on it executes the program instructions in the main function. And nothing else. When
you start the editor you see this:

The micro:bit will start at the first instruction and continue to the end. This makes it very difficult to create
animations, since the program needs to keep running in order to keep changing the animation frame.

The most common solution to this program is to force the main function to never end. You can do this by letting it 'spin'
in a loop forever. This can be done through the forever code, or a simple while loop that continues to execute while
the value of the expression ('true' in this case) is 'true'. Since true is always true, the loop runs forever and you can
ask the micro:bit to work indefinitely. That code looks like this:

The reason for the delay is that the micro:bit runs so fast that without a pause any lights that blink would happen
very fast, and could even cause epiletic fits in some users.

NOTE: If you have registered an event (like 'on button pressed') then its code will still get executed when you pressed the
given button. More on events at a later date...

The solo main approach differs from other platforms. So if your students have experienced the Arduino they will be used to two
functions: setup and loop. You can mimic this approach for them by creating two functions (called setup and loop) and making
main appear thus:

But, to be fair, if your students are confident with the Arduino, they'll probably be teaching you how to convert it!

Random dots an example

Our first example is to create simple random pattern of lights. We will put this in a function on its own
because we are going to use this code again, and it's good practice to isoalte commonly (and often)-used code in a function
so it can be used time and time again.

Notes: The random function is in-built, and returns a random value between 0 and 1. i.e. 2-1.

You can then return to the main function and draw a new screen of random dots whenever the 'A' button is pressed. If you'd like
a hint, the basic code is:

You will notice that after a few presses the whole area is lit. That is because we never un-light anything. There are two
solutions here:

Clear the screen when the user presses the button, but before drawing the new random dots.

Amend the random dots function to include an unplot instruction in the else.

NOTE: The 'for' loops here repeat the inner code for all values of 0, 1, 2, 3, and 4. It is normal in programming to
start counting from 0 and use &lt 5, rather than &lt=4 as it gives a clue as to how many items there are. In this case, 5.
However, it is not normal to force the name of for loop counter. i and j don't make a lot of sense in
this instance, since we're working through X and Y co-ordinates. Alas, I have not found a way to change this.

Invert the whole display. i.e. if the LED is on, switch it off and vice-versa with (and then WITHOUT) using the toggle instruction

Rotate the image clockwise, or anti-clockwise, by 90 or 180 degrees

Use the rotation method to ensure the image is always presented the correct way up

The Compass not an example

In short, don't bother! It appears the micro:bit requires you to re-configure the compass every
time you upload a new program to it. This takes time, and causes anyone to lose interest!

The heat sensor not an example

In short, don't bother! The temperature is detected by examing the ambient temperature of the circuit board. In doing so
the temperature as reporting increases, or decreases, incrementally by 1 degree at a time. Consequently, all attempts at measuring a hot
thing (coffee) compared to a cold thing (metal desk) took several minutes to reach a temperature different enough that it could be used.