Skip to content

Activity

Touch emotion badge

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

Step 1: Make it

What is it?

Add another expression to an emotion badge project using the new micro:bit's touch logo sensor as an extra button

Introduction

Coding guide

What you'll learn

  • How computers take inputs, process them using code and create different outputs
  • How to use the new micro:bit's touch logo like a button input to trigger outputs

How it works

  • This program senses if you press button A and shows a happy face icon on the LED display output.
  • It senses if you press button B and shows a sad face on the LED display.
  • If you touch the gold logo on the front of the new micro:bit, the program detects your finger and shows a surprised face on the LEDs.

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 *
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 pin_logo.is_touched():
9        display.show(Image.SURPRISED)

Step 3: Improve it

  • Change the icons that appear, or draw your own to show different emotions.
  • Create an animated sequence of faces when you press each button.
  • Add different sounds that match each emotion.