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

Term 1 round-up

Week 11 · Review: Term 1 · 3 lessons
3

Review: micro:bit and projects

Computing 7: Units 7.1–7.2, pp. 8–81
GoalRead, trace, correct and plan micro:bit programs that use sensors, buttons and gestures, and name the stages of a project.
New words
threshold · the value in a condition at which the decision changes, such as 10 in temperature() < 10gesture · a movement of the micro:bit that the accelerometer can notice, such as shakesimulator · a program that imitates a device or situation so that people can practise safelysuccess criteria · the list of things the finished project must do
Explanation

A micro:bit has sensors that send numbers or True/False answers to the program. The program keeps asking its question inside while True: and uses if and else to choose the output. Indentation and the colon show which lines belong to the if. Image names such as Image.YES use capital letters, and text such as "Go" needs quotation marks. A project has five stages: plan, design, create, test and evaluate. You write the success criteria in the plan, draw the flowchart in the design and work out the expected outcomes for the test plan before you run anything. A simulator lets you try a program when the real device is not at hand.

Sensor or inputMicroPythonWhat comes back
temperaturetemperature()a whole number of degrees Celsius
lightdisplay.read_light_level()a number from 0 to 255
button A or Bbutton_a.is_pressed()True or False
touch logopin_logo.is_touched()True or False
movementaccelerometer.was_gesture("shake")True or False
Worked examples
QuestionAnswer
goalshow whether the guinea-pig hutch is warm enough
sensortemperature sensor
comparison and thresholdtemperature() < 10
output if yesa cross (too cold)
output if noa tick
Before a program is typed, the problem is broken down. This is the plan for a sign on a guinea-pig hutch. Every row answers one question, and the last three rows are exactly what the flowchart and the program need.
Python
1from microbit import *
2while True:
3    if temperature() < 10:
4        display.show(Image.NO)
5    else:
6        display.show(Image.YES)
Output
a cross below 10 degrees; a tick at 10 degrees or more
This is the program for the plan. The threshold is 10, and the operator < means that exactly 10 degrees is not too cold. So at 10 degrees the else branch runs and the board shows a tick.
Python
1from microbit import *
2while True:
3    if button_a.is_pressed():
4        display.show(Image.HEART)
5    if button_b.is_pressed():
6        display.clear()
7    if accelerometer.was_gesture("shake"):
8        display.show(Image.SMILE)
Output
A: heart. B: blank screen. Shake: smile.
Three if statements in one loop. Press A and a heart appears. Shake the board and the smile replaces it. Press B and the screen clears. The events A, then shake, then B, then A again give the pictures: heart, smile, blank, heart.
Class activity

Paper micro:bit (no computer): draw a 5 × 5 grid and two buttons on paper. A partner reads out the program in the third example one line at a time and then calls events, for example ‘A is pressed’, ‘the board is shaken’ and ‘B is pressed’. After each event you draw what the lights show. Then swap roles and make up a new event list with at least five events that includes pressing A twice in a row. If you have a computer or tablet, you can try the program in an online micro:bit simulator with an adult.

Practice
1
What does the board show when the light level is 119, 120 and 121?
Python
1from microbit import *
2while True:
3    if display.read_light_level() >= 120:
4        display.show(Image.SQUARE)
5    else:
6        display.show(Image.SQUARE_SMALL)
2
The plan says: when B is pressed, scroll the word Safe, wait 2 seconds and then show a tick. Find four mistakes and write the correct program.
Python
1from microbit import *
2while True:
3    if button_b.is_pressed()
4        display.scroll(Safe)
5        sleep(2)
6        display.show(Image.Yes)
3
Write the MicroPython program for this flowchart.
StartIs A pressed?yesnoscroll the word Goshow an arrow pointing rightshow a small squareEnd
4
The hutch sign shows a cross when temperature() < 10 and a tick otherwise. Write the expected outcomes by hand. Then say which test fails if the programmer wrote <= 10 by mistake.
TestTest dataExpected outcome
1temperature 0?
2temperature 9?
3temperature 10?
4temperature 25?