Skip to content

Activity

Flashing emotions

Beginner | MakeCode, Python | Buttons, LED display | Abstraction, Iteration, Sequence

Step 1: Make it

What is it?

Make your feelings really stand out with flashing happy and sad faces.

micro:bit showing a flashing smiley face on its LED display

How it works

  • Like the Emotion badge project, this program shows different emotion images on the LED display output depending on which button input you press.
  • Loops can make sets of instructions run for ever, but here we use a numbered loop to flash the image 4 times to make it really eye-catching.
  • Loops are an important idea in computer programming as they save repeating the same code many times, making your program more efficient. This idea is also called iteration.

What you need

  • micro:bit (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack (optional)

Step 2: Code it

1from microbit import *
2
3while True:
4    if button_a.is_pressed():
5        for x in range(4):
6            display.show(Image.HAPPY)
7            sleep(200)
8            display.clear()
9            sleep(200)
10    if button_b.is_pressed():
11        for x in range(4):
12            display.show(Image.SAD)
13            sleep(200)
14            display.clear()
15            sleep(200)

Step 3: Improve it

  • Make the badge flash more times by making the number 4 larger.
  • Make the flashing faster or slower by changing the delay of 200 milliseconds (0.2 seconds).
  • Make it flash forever.
  • Use different emotion images, or draw your own.