Week 10 · Unit 7.2: Decomposing problems · 3 lessons
2
Shake, tilt and flip
Computing 7: Unit 7.2, pp. 44–81
GoalUse the accelerometer’s gestures in if statements and predict what a gesture program does.
New words
gesture · a particular way of moving the micro:bit, such as a shakeaccelerometer · the sensor that notices movement and which way the board is facingwas_gesture · a question that is true if the gesture has happened since the last time it was askedfreefall · falling, with nothing holding the board up
Explanation
The accelerometer notices how the micro:bit moves and which way it is facing. We will use eight of its gestures: shake, up, down, left, right, face up, face down and freefall. The question accelerometer.was_gesture("shake") is true if the board has been shaken since the last time it was asked. The gesture name is a string, so it goes inside quotation marks and is written in lower case; face up has a space in it. Each gesture can have its own if statement and its own output. As with other sensors, the questions go inside while True so that the program keeps checking.
Gesture
What you do with the micro:bit
shake
shake it
up
hold it upright with the logo at the top
down
hold it upside down with the logo at the bottom
left
tilt it to the left
right
tilt it to the right
face up
lay it flat with the lights facing up
face down
lay it flat with the lights against the table
freefall
the board is falling through the air (never drop a real one)
A parcel carries a micro:bit that raises the alarm if the parcel is dropped. The gesture freefall is detected, and then the program gives two outputs: a picture and a sound. Note the import line.
Event
Which if is true?
Picture shown
lies face up
face up
sleeping face
shaken
shake
surprised face
lies face up again
face up
sleeping face
To predict a gesture program, write the events in order and the picture after each one. The board lies face up, then it is shaken, then it lies face up again.
Class activity
Gesture charades (no computer). Use a book as a pretend micro:bit and mark the logo end with a sticker or a drawing. Your partner calls out gesture names and you act them out with the book: up, down, left, right, face up, face down. Then your partner makes up a short program, for example “left shows an arrow, right shows a different arrow”, and calls gestures while you say what appears. For the freefall gesture, only talk about it – never drop a real device. If you have a micro:bit and an adult to help, try the gestures on the real board.
Practice
1
Copy the table and complete the three missing gestures from their descriptions.
Description
Gesture
tilt it to the left
?
lay it flat with the lights facing up
?
the board is falling through the air
?
shake it
shake
tilt it to the left: left. lay it flat with the lights facing up: face up. the board is falling through the air: freefall.
2
The board is held upright and then turned upside down. What scrolls, in order?