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

Shapes from different inputs

Week 28 · Unit 12: Be an artist · 3 lessons
3

From plan to blocks

Computing 4: Unit 12, pp. 168–179
GoalTurn a three-part algorithm into micro:bit blocks and test each part in turn.
New words
simulator · a program on a computer that shows how the board would behavepause · a block that waits for some milliseconds before the next blockclear screen · a block that switches all the lights offmillisecond · one thousandth of a second, so 1000 ms is 1 second
Explanation

Each part of the algorithm becomes one input block, with the output blocks inside it. Build one part, test it, and then build the next. In a simulator you can press the buttons on the screen to test the program. A pause block waits for a number of milliseconds, and 1000 ms is 1 second. Pauses matter. If two shapes are shown one after another with no pause, the first shape disappears at once and we see only the last one. Use clear screen to turn all the lights off. When you test, press each input and compare what you see with the algorithm. If it is different, find the part with the bug and fix it.

PartStepInstruction
11Start program when button A is pressed
12Show plus
13Pause for 1 second
14Show X
21Start program when the board is shaken
22Show small diamond
23Pause for 3 seconds
24Clear screen
31Start program when the logo is touched
32Play the yawn sound until done
Worked examples
show ledspause (ms)1000show ledson buttonApressedshow ledspause (ms)3000clear screenonshakeplay soundyawnuntil doneon logopressed
The three parts as micro:bit blocks. Part 1 shows the plus, waits 1000 ms and then shows the X. The X stays on, because nothing clears it. Part 2 shows the small diamond for 3000 ms and then clears the screen. Part 3 plays the sound.
TestExpected resultActual resultPassed?
press Aplus for 1 second, then X stays onsameyes
shake the boardsmall diamond for 3 seconds, then blanksameyes
touch the logoyawn sound playssameyes
Test one input at a time. This is the test table for the program.
show ledsshow ledson buttonApressed
What if the pause is missing? Here, part 1 shows the plus and then the X straight away. The plus is on for such a short time that nobody can see it. The test table shows a mismatch, and the fix is to add pause (1000) between the two show blocks.
Class activity

Block cards (with family): write each block on a small card: on button A pressed, show leds plus, pause 1000, show leds X, on shake, show leds small diamond, pause 3000, clear screen. Put the cards in the order of the algorithm for Part 1 and Part 2. Ask somebody to be the board and to follow the cards, holding up a paper shape for each show block and counting the seconds. If you have a computer or tablet, ask a grown-up to help you build the program in a simulator, one part at a time.

Practice
1
Write the blocks for this algorithm: start when button B is pressed; show the big diamond; pause for 2 seconds; clear the screen.
StepInstruction
1Start program when button B is pressed
2Show big diamond
3Pause for 2 seconds
4Clear screen
2
The algorithm says: when buttons A and B are pressed together, show the letter E for 2 seconds and then the small plus. Find the bug in the program.
show ledsshow ledson buttonA+Bpressed
3
What should you see when you press button B? What is on the display one second after the press?
show iconheartpause (ms)500clear screenon buttonBpressed
4
How many seconds of pauses are in this program in all?
show ledspause (ms)1000clear screenpause (ms)500show ledspause (ms)2000on buttonApressed