Project 2First steps20 min
π Magic Buttons - Happy and Sad Faces
Use buttons A and B to show happy and sad faces on the light screen.
Workshop projects (2 of 6)
In this project you'll learn to use the micro:bit's buttons to show different faces! It's like giving your micro:bit feelings.
What are we going to do?
We're going to program the micro:bit so that:
- When you press button A, it shows a happy face π
- When you press button B, it shows a sad face π’
- At the start, it shows a neutral face
The micro:bit's buttons
The micro:bit has two main buttons:
- Button A: On the left
- Button B: On the right

Step 1: Create a new project
- In MakeCode, click "Home" to go back to the main menu
- Create a new project and call it "Button faces"
Step 2: Show a neutral face at the start
First, let's make a neutral face appear when the micro:bit turns on.
- Go to the "Basic" category (blue)
- Drag the "show leds" block into the "on start" block
- Click the little squares to draw a neutral face:

Step 3: Program button A (happy face)
Now let's make a happy face appear when you press button A.
- Go to the "Input" category (pink)
- Drag the "on button A pressed" block to the workspace
- Go to "Basic" and drag a "show leds" inside the button A block
- Draw a happy face by clicking the LEDs:

Step 4: Program button B (sad face)
Now button B for the sad face!
- Back in "Input", drag another "on button A pressed"
- Change button A to button B
- Add a "show leds" inside
- Draw a sad face:

Step 5: Try your program!
- Look at the micro:bit simulator
- Click button A on the simulator - you should see the happy face!
- Click button B on the simulator - you should see the sad face!
- Click the restart button (the circle with an arrow) - the neutral face is back!

Experiment more!
Idea 1: Add more feelings
What happens if you press both buttons at the same time? You can add that too!
- Go to "Input", find "on button A pressed", and change A to A+B
- Add it and draw a surprised or angry face
Idea 2: Add sounds
Give each face its own sound!
- Go to the "Music" category (red)
- Drag "play tone" blocks after each "show leds"
- Choose different tones for each feeling

What have you learned?
- β How to use the micro:bit's A and B buttons
- β How to draw with the LEDs using "show leds"
- β How to make the micro:bit react to different actions
- β That you can make interactive programs
Common problems
π€ A button doesn't work?
- Make sure you chose the right button (for example, A instead of B).
- Check that the "show leds" block is inside the button block.
π€ The face doesn't look right?
- Check that you clicked the right LEDs.
Ready for more adventures?
Fantastic! In the next project we'll make the micro:bit notice when you move it. Go to Project 3: On the move!!