Computer 2

Thursday, March 26, 2026

Micro:bit Gestures and Quiz Prep

Agenda

  1. Learn how to detect gestures on the Micro:bit.
  2. Turn in the movie project and finish the button/tilt project.
  3. Study for the Micro:bit quiz.

Micro:bit Gestures

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.

Gestures to try

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

Example: Detect a Shake

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.

Example: Multiple Gestures

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()

Mixing Gestures with Buttons

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()

Classwork: Finish and Turn In

Complete your current projects before studying for the quiz.

1. Turn In the Movie Project

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.

2. Finish the Button/Tilt Project

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.

3. Study for the Micro:bit Quiz

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:

You can also look at the new example programs in the class repository for more ideas and practice code: c2examples on GitHub.