GoalChoose between show number, show string, show icon and show leds, and trace a program that uses pause and clear screen.
New words
show number · an output block that displays a number, such as the value of a variableshow string · an output block that displays letters and wordspause (ms) · a block that waits; 1000 milliseconds is 1 secondclear screen · a block that switches every LED off
Explanation
The micro:bit can output in several ways. The show number block displays a number, such as the value of a variable. The show string block displays letters and words, and text with a number in it is a string too. The show icon block displays a ready-made picture, such as a heart. For any other pattern, the show leds block lets you click the LEDs that you want lit, such as the little house in the picture. Long numbers and words scroll across the 5 × 5 display. The pause block waits for a number of milliseconds, and clear screen turns all the lights off. The Math group also has a block that picks random true or false.
Worked examples
Coins: the board starts with 3 coins. When button A is pressed it scrolls the word Coins, shows the number of coins for 2 seconds, and then clears the screen.
Step
Display
show string Coins
the word Coins scrolls past
show number coins
3
pause 2000
3 stays for 2 seconds
clear screen
all lights off
The trace shows what the display does in each step.
We need to show
Block
Why
the number 24
show number
it is only a number
the word Go
show string
it is letters
Room 5
show string
it has letters in it
a smiling face
show icon
there is a ready-made smile
Choose the block that matches what we need to show.
Class activity
Human display (groups). Mark a 5 × 5 grid on the floor with tape or chalk. A leader calls ‘show number 7’ or ‘show string Hi’ and the rest of the group stand on squares to draw it, one character at a time. Then the leader calls ‘pause’ and everyone freezes, and ‘clear screen’ and everyone steps off. Try to show a letter T with as few squares as you can.
Practice
1
Which output block is best for each? (a) the number of goals, 4, (b) the word ‘Goal!’, (c) a heart, (d) the text ‘Team 2’
(a) show number, (b) show string, (c) show icon, (d) show string, because it has letters in it.
2
Ana wants the number to stay on the display for 3 seconds before the screen clears. What number should she put in the pause block?
The pause block uses milliseconds. 3 seconds is 3000 milliseconds, so she should write 3000.
3
Which block makes this pattern, and where is it found?
The show leds block, in the Basic group. You click the lights you want on.
4
A variable flag is set with ‘pick random true or false’. How many different values can flag hold? What are they?