One, Two, Three

This lesson will teach the kids how to run different code when you press the buttons on the micro:bit

Teachers Notes

In this lesson the kids will code each button on the micro:bit.

The program will word as follows:

  • When button A is pressed, the LED's will show 1.

  • When B is pressed, the LED's will show 2.

  • When A+B is pressed, the LED's will show 3.

The kids will use the show string block to display the numbers and the Input -> on button pressed block to trigger button presses.

The on button pressed block can be found under the pink Input category. This block allows to to select 3 option from the dropdown namely A, B, A+B which corresponds to each button.

You will use 3 of these blocks. Each for one button

Create your new program

Click on the micro:bit icon on your toolbar or go to https://makecode.microbit.org/ on your browser.

Click on "New Project". The MakeCode editor will appear

Delete the on start and forever blocks by dragging it to the toolbar

Show 1 when I press button A

Kids task

You will need to program your micro:bit so that when you press button A, the number 1 is displayed

Click on the pink Input category in the toolbox

Drag the on button press block and move it to your workspace

Your workspace should look like the image below

Find the show string block under Basic

Drag the show string block and move it inside the on button pressed block

Type in 1 in the show string block

On the simulator side, press the A button and you will see 1 display

Show 2 when I press button B

Kids task

You will now need to program your micro:bit so that when you press button B, the number 2 is displayed

Drag another on press button block to your workspace

Click on the drop down by A and you will see 3 options displayed.

Select B from the dropdown

What this means is that when you press button B, something will happen

Drag a show string block to the on button button B pressed code block.

Type 2 in the show string code block.

On the simulator side, press button B and the LED should display 2

Show 3 when I press button A+B

Kids task

Lastly you will now need to program your micro:bit so that when you press button A and button B, the number 3 is displayed

Once again, drag the on button pressed code block to your workspace

Select the option A+B from the drop down

Drag a show string code block to the on button A+B pressed code block.

Type 3 on in the show string code block

In the simulator, press the A+B Button and the LED should display 3

Save, download and run your code

Save you code as 1 2 3 and press save to download.

Drag your code file named microbit-1-2-3.hex to the MICROBIT(D:) folder to upload your code to your micro:bit.

Test your micro:bit by pressing Button A, then Button B then both button A and button B at the same time.

Last updated