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

Predict the sound

Week 18 · Unit 8: Be a musician · 3 lessons
2

Predict what changes

Computing 3: Unit 8, pp. 119–134
GoalRead a micro:bit algorithm and predict what happens when some lines are changed.
New words
algorithm · a list of steps that a computer followspredict · to say what will happen before you run the programchanged line · a step that is different from the same step in another algorithm
Explanation

An algorithm for the micro:bit begins with the input that starts it. Then it lists the outputs in order, one line at a time. When someone changes an algorithm, we can predict the new result without running the program. First find what is different: a number, a word, a choice from a list or the order of the lines. Then say what each change does. A bigger volume number means a louder sound, a new word means new letters scroll, and a line that moves happens at a different time. Lines that did not change give the same result as before.

Algorithm 1on buttonApressedshow iconhouseset volume50play soundtwinkleuntil doneshow stringHiAlgorithm 2on buttonApressedset volume200play soundtwinkleuntil doneshow stringHelloshow iconhouse
Worked examples
StepAlgorithm 1
1Start when button A is pressed
2Show icon house
3Set volume to 50
4Play sound twinkle until done
5Show string “Hi”
Algorithm 1 starts when button A is pressed. It shows a house, sets a quiet volume of 50, plays the twinkle sound until it is finished and then scrolls the word Hi.
What changedAlgorithm 1Algorithm 2What happens now
the volume50200the twinkle sound is much louder
the wordHiHelloa longer word scrolls
show icon housefirst outputlast outputthe house appears at the end and stays on the lights
Algorithm 2 is Algorithm 1 with three changes. Everything else is the same, so we only have to predict the three differences.
ABend of Algorithm 2
Algorithm 2 predicted result: press A, the lights stay dark while the twinkle sound plays loudly, the word Hello scrolls, and then the house appears and stays. The button and the sound are the same as before.
Class activity

Predict and perform (in pairs): one of you reads Algorithm 1 aloud, line by line, and the other performs it: stand still until the cue (the input), make a house shape with your arms for the icon, hum a tune quietly and then say the word. Now read Algorithm 2. Before you act, say what you expect to be different. Then act it out. Was your prediction right? Which of the three changes was the hardest to notice?

Practice
1
Algorithm X: 1 Start when button A is pressed. 2 Show icon heart. 3 Play sound happy until done. Algorithm Y: 1 Start when button B is pressed. 2 Show icon heart. 3 Play sound sad until done. Which lines changed? What is different when the program runs?
2
Algorithm 1 is changed so the volume is 0 and the word is Bye. Predict the outcome.
Algorithm 1 changedon buttonApressedshow iconhouseset volume0play soundtwinkleuntil doneshow stringBye
3
How many lines are different in these two algorithms?
Oneon buttonApressedshow iconduckpause (ms)1000clear screenTwoon buttonBpressedshow iconduckpause (ms)3000clear screen
4
Why can we predict what a changed algorithm does without running it?