AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Micro:bit inputs and jobs

Week 20 · Unit 8: Be an innovator · 3 lessons
2

A program for a job

Computing 6: Unit 8, pp. 106–123
GoalPlan a micro:bit program for a real job with an input, process and output table, then write and trace its blocks.
New words
requirement · something that the program must doplan · a short description of the inputs, the process and the outputs before we write the programreset · to put a variable back to its start valuetrace table · a table that shows the value of the variables after each step
Explanation

A good programmer plans before writing blocks. First, say what job the program must do. Second, list the inputs, the process and the outputs in a table. Third, decide which variables are needed and what each event will do. Fourth, write the algorithm in short steps, then turn each step into blocks. At the end, trace the program with some test presses and check each answer by hand. A counter often needs a reset, so that a new count can start from 0. When the program has to choose between two outputs, add an if block, and test the values on both sides of the condition.

PartPlan for a laps counter
Jobcount the laps run, and show the distance
Inputbutton A (a lap is done), button B (show distance), A+B (start again)
Processlaps = laps + 1; distance = laps × 400
Outputnumber of laps, or distance in metres
Worked examples
Achangelapsby1show numberlapson buttonApressedBshow numberlaps×400on buttonBpressedA+Bsetlapsto0show numberlapson buttonA+Bpressed
This laps counter is for a running track where one lap is 400 m. A adds a lap, B shows the distance and A+B resets. Suppose that A is pressed three times, then B, then A+B.
Presslaps afterBoard shows
A11
A22
A33
B31200
A+B00
The trace of the laps counter. After B the board shows 3 × 400 = 1200.
changecupsby1show iconyesshow numbercupsifcups≥8thenelseon buttonApressed
A second job: help a runner to drink 8 cups of water in a day. Each press of A adds a cup. The board shows the number of cups, and when it reaches 8 it shows yes. Suppose that A is pressed 9 times. The board shows 1 to 7, and then it shows the yes icon at the 8th and at the 9th press, because the condition cups ≥ 8 is true both times.
Class activity

Plan a job (no computer): choose one job, such as a score keeper for a team game, a counter for the visitors at a school fair or a tool to count the pages read in a week. Draw a plan table with the job, the inputs, the process and the outputs. Write the algorithm in short numbered steps. Give your plan to a partner, who traces it with a list of six presses and checks the results. Did your partner find a missing step, such as a reset? Improve the plan. If you have a computer or tablet, build your program in a micro:bit simulator.

Practice
1
Complete the plan for a program that counts the visitors to a school fair and shows the total. What is the process?
PartPlan
Jobcount the visitors
Inputbutton A pressed
Process?
Outputshow number visitors
2
A tray holds 30 eggs. A is pressed for each egg that is sold, and B shows how many are left. A is pressed 7 times and then B is pressed. What does the board show?
Achangesoldby1show numbersoldon buttonApressedBshow number30−soldon buttonBpressed
3
Write an algorithm in numbered steps for a score keeper. Button A adds 1 to the score and shows it. Button B starts again at 0.
4
A plan says: button A adds 1 to cups, and the program shows yes if cups ≥ 8. Which values of cups would you test, and what do you expect?