How to use micro:bit buttons to change the display

Description

This example shows how to code the buttons on the micro:bit. There’s not much to it, so it’s a great place to start if you are new to the micro:bit and don’t know where to start. In this exercise, we will use the buttons to display something on the LED array. 

Programming Language

MakeCode Blocks

Difficulty Level

Beginner

Age Range

9 and up

Materials

Optional tools:

Programming the micro:bit

Develop the problem statement

The problem statement for this project is project is this:

How can I code the  buttons to display a value then erase the value?

Write the algorithm

The algorithm should be a standard text version of what the code should do.  Here is my version:Here is the algorithm:

  • When Button A pressed:
    • Display a ‘6’
  • When Buttons A and B are pressed at the same time:
    • Erase the LED array

The pseudocode  in this case is the same as the algorithm since it is a very short program.

Write and test the code

Here is the sample code for this project.