Micro:bit Gestures and Quiz Prep
Respond to how the Micro:bit is moved or oriented.
In addition to buttons and the raw accelerometer, the Micro:bit can recognize named gestures — specific movements or orientations like shaking, tilting face-up, or going into freefall. You do not need to read numbers yourself; the Micro:bit figures out the gesture for you.
Use accelerometer.is_gesture("shake") to check whether the
named gesture is currently happening. It returns True or
False, so it works naturally inside an
if statement.
| Gesture name | What it detects |
|---|---|
"shake" |
The Micro:bit is being shaken |
"up" |
The logo edge is pointing up |
"down" |
The logo edge is pointing down |
"left" |
The Micro:bit is tilted to the left |
"right" |
The Micro:bit is tilted to the right |
"face up" |
The LED side is facing upward (flat on a table) |
"face down" |
The LED side is facing downward |
from microbit import * while True: if accelerometer.is_gesture("shake"): display.show(Image.SURPRISED) sleep(500) else: display.show(Image.HAPPY)
The sleep(500) gives the surprised face time to show before
the loop checks again. Without it the display would flicker.
from microbit import * while True: if accelerometer.is_gesture("shake"): display.show(Image.SURPRISED) sleep(500) elif accelerometer.is_gesture("face down"): display.show(Image.ASLEEP) elif accelerometer.is_gesture("face up"): display.show(Image.HAPPY) else: display.clear()
You can check gestures alongside button presses in the same
while True loop — just add more elif branches.
from microbit import * while True: if button_a.is_pressed(): display.show(Image.HEART) elif button_b.is_pressed(): display.show(Image.ARROW_E) elif accelerometer.is_gesture("shake"): display.show(Image.SURPRISED) sleep(500) else: display.clear()
Complete your current projects before studying for the quiz.
If you have not already done so, make sure your Micro:bit movie project
(from March 12) is uploaded to your OneDrive
folder. The file should be named lastname_movie.py.
Continue working on the button and tilt project from
March 23. The file should be named
lastname_button_tilt.py.
When you have met all the requirements, try adding a gesture to your program. For example, shaking the Micro:bit could show a surprise image, or holding it face-down could clear the screen.
Upload the finished file to your OneDrive folder when you are done.
After turning in the button/tilt project, use the rest of class to review for the upcoming Micro:bit quiz on Monday, March 30. The quiz will cover:
display.scroll() and
display.show()
display.show())
button_a.is_pressed()accelerometer.get_x()accelerometer.is_gesture()You can also look at the new example programs in the class repository for more ideas and practice code: c2examples on GitHub.