GoalPlan, build and test a sound board that has three inputs, each with its own icon and sound.
New words
sound board · a program that plays a different sound for each inputplan · to decide what to build before you build ittest · to try each part to see if it works
Explanation
A sound board plays a different sound for each input. Our sports day sound board has three inputs: button A, button B and shake. Plan it first on paper. For each input choose an icon, a volume and a sound or melody. Then build one script at a time and test it before you go on. When everything works, make a change and predict what will happen before you run it. If you code with a partner, one can build while the other checks the plan.
Input
Icon
Volume
Sound
button A
target
120
slide
button B
giraffe
80
spring
shake
diamond
200
wedding melody
Worked examples
Here is the code for button A and button B. Each script ends by clearing the screen.
The third script starts with a shake. A melody comes from a different list from the sounds, so we use “start melody”. Start melody does not wait for the tune to end, so a pause of 2000 ms keeps the diamond on the lights before the screen is cleared. The whole program has three scripts, one for each input.
Change
Prediction
B: volume 80 to 200
the spring sound is louder; A and shake do not change
A: icon target to ghost
a ghost appears when A is pressed
shake: melody wedding to birthday
another tune plays when you shake the board
Test and change. After testing, we make one change and predict the result.
Class activity
Paper sound board (in pairs): draw a micro:bit with buttons A and B on paper. Make three cards: “A: show target, slide”, “B: show giraffe, spring”, “shake: show diamond, wedding”. One of you is the micro:bit and does what the cards say when the other one does an input (taps, or shakes the paper). Swap roles. Then change one card, predict what the micro:bit will do and test it. What did you learn from working together? If you have a computer or tablet, ask a grown-up to help you build it in a simulator.
Practice
1
In the sports day sound board, how many scripts are there, and what starts each one?
Three. They start with button A pressed, button B pressed and a shake.
2
Add a fourth input to the sound board: the logo. When the logo is pressed, it should show a ghost and play the giggle sound at volume 90. Which blocks go in the gaps?
show icon [ghost v], set volume (90), play sound [giggle v] until done. (The volume block must come before the sound. A clear screen block can be added at the end.)
3
This script plays too loudly. What is the mistake?
The set volume block is after the sound, so it comes too late. It should come before “play sound”.
4
Why is it a good idea to test each script before you build the next one?
Then a mistake is found early and is easy to fix, because it can only be in the script you just built.