Controlling a device with a micro:bit or similar

Computer Science · Key Stage 2 · The School

A tiny computer you can hold

A micro:bit is a small computer with buttons, lights and sensors built in. A program on a laptop is different. A program on this device does something you can see and touch: lights flashing, a message scrolling, a buzzer sounding. Holding the result in your hand makes a bug far easier to notice too. A wrong light or a silent buzzer is obvious the moment it happens.

Buttons as input

The two buttons on a micro:bit are simple inputs. "When button A is pressed, show a happy face" reacts the instant the button is touched. Different buttons, or different combinations, can trigger different actions. Pressing both buttons at once can even be its own separate event. It gets its own separate rule too.

Using a built-in sensor

Devices like this often include a built-in sensor. It might detect shaking, or tilting. "When the device is shaken, show a random number" turns it into a tiny dice. The sensor supplies the input. The program decides what to do with it. A light sensor or a sound sensor works the very same way. Each one just supplies a different kind of input. Swapping the sensor never changes how the program itself is structured.

Testing and improving a step counter

A first attempt at a step counter uses the shake sensor. It counts far too many steps. It reacts to every small wobble as well as real steps. Adding a short pause after each count helps. The pause makes it ignore wobbles right after a real step. That brings the count much closer to correct. Testing on a real walk is what revealed the problem in the first place.

The School — all subjects · Knowledge map