Skip to content

Activity

Sound emotion badge

Beginner | MakeCode, Python | Buttons, LED display, Speaker, Touch logo | Abstraction, Input/output

Step 1: Make it

What is it?

Make an emotion badge that expresses how you feel in sounds as well as pictures.

Introduction

Coding guide

What you'll learn

  • How to use the new micro:bit's built-in sounds as outputs to add personality and expression to your projects.

How it works

  • The micro:bit with built-in speaker can play new expressive sounds. This project plays a happy sound when you press input button A to match the happy icon on the LED display output.
  • It plays a sad sound when you press button B to match the sad face icon.
  • When you press the touch logo, it plays the 'spring' sound to match the surprised face on the LED display.

What you need

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

Step 2: Code it

1from microbit import *
2import audio
3
4while True:
5    if button_a.is_pressed():
6        display.show(Image.HAPPY)
7        audio.play(Sound.HAPPY)
8    if button_b.is_pressed():
9        display.show(Image.SAD)
10        audio.play(Sound.SAD)
11    if pin_logo.is_touched():
12        display.show(Image.SURPRISED)
13        audio.play(Sound.SPRING)

Step 3: Improve it

  • Experiment with the different new expressive sounds like 'giggle', 'hello' and 'twinkle'.
  • Modify the program with different emotion icons, or draw your own.
  • Add an animation to go with each expression.