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

Loops and light shows

Week 29 · Unit 12: Be an artist · 3 lessons
3

Plan and test a show

Computing 4: Unit 12, pp. 168–179
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.

StepInstruction
1Start program when button B is pressed
2Repeat 2 times
3 Show the small star, wait 0.4 seconds
4 Show the big star, wait 0.4 seconds
5Show the heart, wait 1 second
6Clear screen
Worked examples
show ledspause (ms)400show ledspause (ms)400repeat2timesshow iconheartpause (ms)1000clear screenon buttonBpressed
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.
TestExpectedActualPassed?
press Bstar twinkles twice, heart 1 s, blankstar twinkles once, heart 1 s, blankno
after the fixstar twinkles twice, heart 1 s, blankstar twinkles twice, heart 1 s, blankyes
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 robotInput or output?Example of use
camerainputsees a colour card
microphoneinputhears a clap
wheelsoutputdrive forward
speakeroutputsays “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?
show ledspause (ms)300clear screenpause (ms)200repeat3timesshow iconheartpause (ms)1000clear screenon buttonApressed
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.
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.
StepInstruction
1?
2?
3?
4
The test expected 3 flashes but the tester counted 2. Find the bug.
show ledspause (ms)500clear screenpause (ms)500repeat2timeson buttonApressed