GoalReview inputs and outputs, music blocks, groups of blocks and working in a team.
New words
input · what starts a program, such as a button press or a shakeoutput · what the board does, such as showing an icon or playing a soundvolume · how loud a sound is, from 0 to 255
Explanation
A micro:bit program waits for an input. Then it gives outputs in the order of the blocks. Hat blocks such as “on button pressed” and “on shake” are in the Input group. “Show icon” and “clear screen” are in the Basic group. “Set volume” and “play sound until done” are in the Music group. A volume block must come before the sound it changes. Volume 0 is silent and 255 is the loudest. When a team builds a program, one person builds while the other checks, so there are fewer mistakes.
Worked examples
Step
Algorithm Q
1
Start when button A is pressed
2
Show icon asleep
3
Set volume 30
4
Play sound yawn until done
5
Clear screen
Code Q is the sleepy pet. When button A is pressed, it shows a sleeping face, sets a quiet volume, plays a yawn until it is finished and clears the screen.
Code R is Code Q with three changes: it starts with button B, the volume is loud and the sound is a giggle. The icon and the clear screen block are the same.
Block
Group
on shake
Input
show icon
Basic
set volume
Music
clear screen
Basic
Each block belongs to a group.
Class activity
Pet box (in pairs): one of you is the micro:bit, the other gives inputs. Make cards for Code Q and Code R. Tap the left shoulder for A and the right shoulder for B. Do what the cards say: close your eyes and yawn quietly for Q, close your eyes and giggle loudly (but not shouting) for R. Then change one card, for example the volume of R from 250 to 60, predict how it will sound, and test. Which pair member found the mistakes? Did kind words help?
Practice
1
Write the algorithm for Code S.
1 Start when buttons A and B are pressed. 2 Show icon fabulous. 3 Set volume 100. 4 Start melody jump up repeating once. 5 Clear screen.
2
How loud is Code R compared with Code Q?
Code R is much louder. Its volume is 250 and the volume in Code Q is 30. The highest volume is 255.
3
The program should play a happy sound after the icon. Which block fills the gap, and in which group is it?
play sound [happy v] until done, in the Music group.
4
Name two ways a team helps when coding.
For example: someone checks the code and finds mistakes, and the team shares ideas and skills.