GoalUse decomposition to split a micro:bit gadget into its parts before writing any steps.
New words
micro:bit · a small programmable board with 25 lights, two buttons and sensorsdecomposition · breaking a task into smaller partscomponent · one part of a bigger probleminput · what the board senses, such as a button press, a shake or a touch on the logo
Explanation
A micro:bit is a small programmable board with 25 lights, two buttons and sensors. Before we write a program for it, we use decomposition: we break the job into parts. For a flashing gadget the parts are the input that starts it, the picture it shows, how long the picture stays on, how long the screen stays blank and how many flashes there are. These parts are the components. A bag light for walking home must do two different things. Button A flashes a left arrow quickly. Button B flashes a stop sign slowly. Each behaviour has its own input and its own picture, so we will write two separate algorithms. Small parts are much easier to write and to check.
input→picture→time on→time off→number of flashes
Worked examples
Component
Turn left
Stop
Input that starts it
button A
button B
Picture
left arrow
stop square
Time on
0.5 seconds
2 seconds
Time off (blank screen)
0.5 seconds
1 second
Flashes in all
6
3
The two behaviours of the bag light, split into components. Each column will become one algorithm.
When button A is pressed, the board flashes this arrow. It points to the left, so people can see where the walker will turn.
When button B is pressed, the board flashes a square made of the 16 lights round the edge. It means “I am stopping”.
Class activity
Decompose a gadget (with family): think of a gadget that flashes or beeps, such as a reminder that flashes when the plants need water or a toy that beeps when it is shaken. Write the components on a card: input, picture or light, time on, time off, how many times. Fill in the card. Give it to another person. Could they act out the gadget from your card alone?
Practice
1
A wake-up gadget works like this: when the logo is pressed, it shows a sun for 1 second, leaves the screen blank for 2 seconds, and does this 5 times in all. Fill in the components.
Component
Wake-up gadget
Input that starts it
?
Picture
?
Time on
?
Time off (blank screen)
?
Flashes in all
?
Input: the logo is pressed. Picture: a sun. Time on: 1 second. Time off: 2 seconds. Flashes in all: 5.
2
Which component is missing from this description? “When button A is pressed, show a heart. Then leave the screen blank for 1 second. Do this 3 times.”
The time on: it does not say how long the heart stays on the screen.
3
Why do we write two algorithms for the bag light and not one?
The two behaviours start with different inputs (button A and button B) and show different pictures for different times, so each behaviour has its own algorithm.
4
What do you write for the input if a gadget must start when the board is shaken? Draw the picture you would show for a gadget that shows a smile.
Input: the board is shaken. A smile, for example: two eyes in row 2 and a curved mouth in rows 4 and 5.