Skip to content

Activity

Get silly

Beginner | MakeCode, Python | Accelerometer | Input/output

Step 1: Make it

What is it?

Expand the range of emotions you can show – jump up and down to show that you’re feeling silly!

micro:bit being shaken and showing a silly face on its LED display

How it works

  • Like the Emotion badge, this program shows a happy or sad face depending on which button input you press, A or B.
  • The micro:bit has other inputs, such as sensors.
  • This program uses the micro:bit’s accelerometer input to measure forces and sense when it’s shaken.
  • When the accelerometer senses sudden movement the program makes the silly face appear on the LED display output.

What you need

  • micro:bit (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack (optional)
  • some energy to shake, jump or get silly

Step 2: Code it

1from microbit import *
2
3while True:
4    if button_a.is_pressed():
5        display.show(Image.HAPPY)
6    if button_b.is_pressed():
7        display.show(Image.SAD)
8    if accelerometer.was_gesture('shake'):
9        display.show(Image.SILLY)

Step 3: Improve it

  • Use different built-in emotions images like MEH, CONFUSED or ANGRY.
  • Show another emotion when you press buttons A and B together.
  • Add new emotions using the LED display to draw your own pictures like we did in Animated animals.
  • The accelerometer can sense other ‘gestures’ such as ‘freefall’ and whether it’s tilted left or right – try them out. Find out more about gestures in micro:bit Python here.