GoalWrite the requirements for a micro:bit idea, choose the part to build first, and trace that first prototype by hand.
New words
requirement · something the program must do, written so that you can test itprototype · an early, simple version of a program, made to test an idea before the whole program is builtinterface · the part of a program that the user sees and presses, such as the buttons and the lights
Explanation
A micro:bit is a small computer with inputs, such as the buttons A and B and the shake sensor, and outputs, such as its 25 lights. Before you build a program for it, write down the requirements: what must the program do, and what will the user press or see? Then choose one small part to build first. This early version is a prototype. It may cover just one requirement. It may even be a dummy screen that shows the planned look, with no working code behind it. A prototype is cheap to make and quick to test, so mistakes in the idea show up early. If two micro:bits need to talk by radio, they must be set to the same group number, and this is better added after the first part works.
Part of the idea
On the micro:bit
Input
button A, button B, shake
Process
a variable that stores a number, an IF that chooses
Output
the 5 × 5 lights: a number, a word or an icon
Worked examples
No.
The micro:bit must …
Input
Output
1
count every jump and show the count
shake
the number
2
start again from 0
button B
the number 0
3
praise the skipper at 10 jumps or more
shake
a happy face
Requirements for a skipping-rope jump counter. A micro:bit is clipped to the rope handle, and every jump shakes it. The three requirements are numbered, so that each one can be tested on its own. Requirement 1 is the best one to build first, because the others depend on a number that is already counted.
The first prototype covers requirement 1 only. When the program starts, jumps is set to 0. Each shake adds 1 and shows the new number. The user shakes three times, so the lights show 1, then 2, then 3. Pressing B does nothing yet, because requirement 2 is not built.
A prototype of the interface only. This prototype does not count anything. It shows the user how the happy face for requirement 3 will look, when button A is pressed. It is useful for deciding whether the face is clear enough before the code behind it is written.
Class activity
Requirements on cards (no computer). Pick an invented micro:bit idea, such as a sign for a bedroom door or a counter for laps. Write each requirement on its own card: one sentence with an input and an output. Put the cards in the order in which you would build them, and give one reason for the first card. Swap with a partner: can they say what the first prototype would do, and what the lights would show after one press or one shake?
Practice
1
A sign for a bedroom door must show a yes icon when button A is pressed (come in), a no icon when button B is pressed (busy), and a sad face when the micro:bit is shaken (door closed). Write the three requirements and say which you would build first, and why.
Requirement 1: when A is pressed, show the yes icon. Requirement 2: when B is pressed, show the no icon. Requirement 3: when the micro:bit is shaken, show the sad face. Any of the three can come first because they do not depend on each other. A good first prototype is requirement 1, because it is the smallest and tests that a button can change the lights.
2
The user presses button A three times. What do the lights show after each press?
After the first press 2, after the second 4, and after the third 6. Each press adds 2 to score and then shows score.
3
Which of these statements about a prototype are true? (a) It must contain every feature. (b) It can show only how the screen looks. (c) It is tested before more is added. (d) It can be a first version of one requirement.
(a) is false: a prototype may be only a small part. (b) is true. (c) is true. (d) is true.
4
Explain why it is cheaper to test a prototype of one requirement than to build the whole program first.
If the idea is wrong or the code has a fault, you find it after a small amount of work. If you had built everything first, you would have to search through the whole program and perhaps change many parts.