Example Code for micro:bit-Key Detection Function (Query)
Last revision 2025/12/31
This guide demonstrates how to use Makecode to detect key touches on a micro:bit and display a heart pattern on its LED matrix when key 2 is touched, including necessary hardware and software preparations.
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

Result
Show a "heart" pattern on micro:bit LED matrix when key 2 is touched.
Was this article helpful?
