Example Code for micro:bit-Read Keyboard Value (Basic mode)

Last revision 2025/12/31

This article provides a comprehensive guide to reading keyboard values using micro:bit in basic mode. The guide covers hardware and software preparation, including the installation of the Makecode library and integration with the Mind+ platform. It offers a clear wiring diagram and showcases sample code for reading numerical values from key inputs. The result section demonstrates how pressing a key on the micro:bit board will return its corresponding numerical value, making it an excellent resource for beginners looking to explore the capabilities of the micro:bit and expand their programming skills.

Hardware Preparation

  • Math & Automatic expansion board for micro:bit, Quantity: 1
  • micro:bit, Quantity: 1

Software Preparation

Makecode graphical programming, Mind+ platform.
Makecode Library Address.
About how to install a software library?

Wiring Diagram

No specific wiring required (touch keys are integrated on the board).

Other Preparation Work

Install the Makecode library from https://github.com/DFRobot/pxt-Math-Automatic.
About how to install a software library?

Sample Code

Read Keyboard Data (Basic mode)
Show Key Value
Key Value in basic mode:

Key Label Value (numerical)
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
+ 10
- 11
× 12
÷ 13
= 14
DFlogo 15

Result

Press a key then you will get the related key value. For instance, press key 2, then you get its value "2".

Was this article helpful?

TOP