Science Oxford Logo

Creature Circuits - Responding to Movement

Accelerometer

The micro:bit has an accelerometer - it knows when it is being moved around.

You can, for example, make your creature's LED eyes light up when the micro:bit is shaken!

Try the code ideas below, then think about how you could add the accelerometer into your own program.


MakeCode

on shake vs if shake

These two blocks of code are equivalent.

The one on the right can be more useful, because you can use it to build more complex programs


Python

Test out this code:

from microbit import *

while True:
  if accelerometer.was_gesture("shake"):
    display.show(Image.DUCK)

Try these other gestures!

"up", "down", "left", "right", "face up", "face down", "freefall", "3g", "6g", "8g", "shake"