GoalPlan a light show as an algorithm, build and test it, and say how robots use inputs and outputs.
New words
algorithm · a plan with steps in ordertest table · a table that compares the result we expect with the result we getprogrammable device · a device that follows a program, such as a micro:bit or a robot
Explanation
A good light show starts with a plan. Write the algorithm as numbered steps. Say which input starts the show and which outputs come next. Then build the blocks, one part at a time. Run the program and fill in a test table. If the expected result and the actual result are different, find the block that is wrong and fix it. Then test again. Programmable robots work in the same way. A robot has inputs, such as a camera or a microphone, and outputs, such as wheels or a speaker. Its program decides what the outputs do when an input arrives.
Step
Instruction
1
Start program when button B is pressed
2
Repeat 2 times
3
Show the small star, wait 0.4 seconds
4
Show the big star, wait 0.4 seconds
5
Show the heart, wait 1 second
6
Clear screen
Worked examples
The algorithm above, built as blocks. The two rounds of stars take 0.8 s × 2 = 1.6 seconds. The heart adds 1 second, so the whole show lasts 2.6 seconds, and then the screen is blank.
Test
Expected
Actual
Passed?
press B
star twinkles twice, heart 1 s, blank
star twinkles once, heart 1 s, blank
no
after the fix
star twinkles twice, heart 1 s, blank
star twinkles twice, heart 1 s, blank
yes
The test table shows a bug. The tester expected two twinkles, but the star twinkled only once. The loop was set to repeat (1) times. The fix is to change the number to 2 and test again.
Part of the robot
Input or output?
Example of use
camera
input
sees a colour card
microphone
input
hears a clap
wheels
output
drive forward
speaker
output
says “hello”
A programmable robot has inputs and outputs too. Its program links them.
Class activity
Light show planner (with family): plan a show with a grown-up on paper. Choose the start input, a picture for a 5 × 5 grid, a pause time and a number of repeats. Write the algorithm in numbered steps. Then swap with another person, who follows the steps with paper pictures and counts the seconds. Was anything unclear? Fix the steps and try again. If you have a computer or tablet, ask a grown-up to help you test it in a simulator.
Practice
1
How long does this whole program take?
3 rounds of 300 + 200 = 500 ms give 1500 ms. The heart and its pause add 1000 ms. The total is 2500 ms, which is 2.5 seconds.
2
A robot lawnmower has a rain sensor, a bump sensor, a motor that turns its blades and a lamp. Sort the parts into inputs and outputs.
Inputs: the rain sensor and the bump sensor. Outputs: the blade motor and the lamp.
3
Write an algorithm in steps: when button A is pressed, flash the plus 3 times, 0.5 seconds on and 0.5 seconds off, and then show a happy face.
Step
Instruction
1
?
2
?
3
?
1. Start program when button A is pressed. 2. Repeat 3 times: show plus, wait 0.5 s, clear screen, wait 0.5 s. 3. Show happy face.
4
The test expected 3 flashes but the tester counted 2. Find the bug.
The loop is set to repeat 2 times. Change it to repeat 3 times and test again.