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

Term 2 review

Week 21 · Review: Term 2 · 3 lessons
3

Music on the micro:bit

Computing 3: Units 5–8, pp. 79–134
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.

Code Qon buttonApressedshow iconasleepset volume30play soundyawnuntil doneclear screen
Worked examples
StepAlgorithm Q
1Start when button A is pressed
2Show icon asleep
3Set volume 30
4Play sound yawn until done
5Clear 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 Ron buttonBpressedshow iconasleepset volume250play soundgiggleuntil doneclear 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.
BlockGroup
on shakeInput
show iconBasic
set volumeMusic
clear screenBasic
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.
Code Son buttonA+Bpressedshow iconfabulousset volume100start melodyjump uprepeatingonceclear screen
2
How loud is Code R compared with Code Q?
3
The program should play a happy sound after the icon. Which block fills the gap, and in which group is it?
on buttonBpressedshow iconhappy?clear screen
4
Name two ways a team helps when coding.