GoalWrite and check light-grid programs, use a sub-routine in a plan and tell the kinds of prototype apart.
New words
pattern recognition · spotting what repeats or stays the same, so that code can be copied and editedevolutionary prototype · a first version that is improved again and again until it becomes the final productthrowaway prototype · a rough version made to answer a question and then thrown awaybrightness · a number from 0 (off) to 9 (full) that sets how brightly a light shines
Explanation
A picture on the 5 × 5 lights is written as five rows of five digits, with a colon after every row except the last. A 9 is a bright light, a 0 is off and the numbers between give less brightness. A sequence is a list of pictures with sleep() between them, and sleep(1000) is one second. display.clear() switches the lights off at the end. Spotting a pattern lets you copy a block of code and change only the parts that differ. A sub-routine is drawn as a box in the main flowchart, and its own flowchart shows the steps. Before the final version, a prototype is tested with users and with a test plan, and the project is evaluated. A prototype that is thrown away is called a throwaway prototype, and one that grows into the final product is an evolutionary prototype.
Part of the plan
Question to ask
project plan
what must it do, what are the inputs and the outputs?
grids and flowchart
what does each image look like, and in what order?
code
does every row have five digits and every image a sleep()?
Plan the letter Z. The top row is all on, the bottom row is all on, and one light in each middle row moves one step to the left. Write 9 for a light that is on and 0 for a light that is off. Check that there are five digits in every row and a colon after every row except the last.
A model beacon pulses when A is pressed. The sub-routine pulse shows the centre light at brightness 3, then 6, then 9, with a wait of 0.3 second after each image, and then clears the screen. The main flowchart stays short, and each press uses the sub-routine for 3 × 0.3 = 0.9 seconds.
Situation
Kind of prototype
Why
A village hall tests only the booking form of a new website with six visitors and then builds the real form
throwaway
only one part is tested, and the prototype is thrown away
A team gives a school a first working lunch-ordering program and improves it after each month of feedback
evolutionary
the same program grows into the final product
A cardboard model of a bird box to check its size
throwaway (physical)
it answers a question about size and is not kept
Three prototypes sorted by kind. To decide, ask what the makers want to learn and whether the prototype will be kept. In every case users try it, and their feedback is used to improve the product.
Class activity
Light show on paper (no computer): plan a sequence of three images for a model such as a sunrise, a rocket or a bicycle light. Draw each image on its own 5 × 5 grid, using brightness numbers between 0 and 9. Write a flowchart with the waits and then the whole program. Swap with a partner, who traces your code and draws the three pictures from it. Compare the drawings with your grids. Finally write two test plan rows and one improvement that a user might suggest. If you have a computer or tablet, you can try your program in a micro:bit simulator.
Practice
1
How long does the program wait after each image? Which light is on when the program has finished, and at what brightness?
It waits 300 ms (0.3 s) after the first image, 600 ms (0.6 s) after the second and 300 ms (0.3 s) after the third. There is no display.clear(), so the third image, the centre light at brightness 9, stays lit after the program ends.
2
Write the five rows of code for the picture on the board.
Image("90009:90009:90009:09090:00900"). Write a 9 for every light that is on.
3
The program should show a big X for half a second and then clear the screen, but the picture is wrong. Find the mistake and write the correct line.
The last row has only four digits (9009). Every row needs five digits, so it must be 90009. The correct line is display.show(Image("90009:09090:00900:09090:90009")).
4
A sign should do this: when button B is pressed, the board shows Image.ARROW_S (an arrow pointing down) for 2 seconds and then clears the screen. Write the expected outcomes for the test plan.
Test
Test data
Expected outcome
1
B pressed once
?
2
no button pressed
?
3
B held down for several seconds
?
Test 1: the down arrow shows for 2 seconds, then the screen clears. Test 2: nothing happens and the screen stays clear. Test 3: the program keeps checking the button, so the arrow shows again each time it finishes while B is still held.