Example Code for micro:bit-Math Calculator
Last revision 2025/12/31
This article provides a comprehensive guide on transforming a micro:bit into a Math Calculator using a math expansion board and Makecode programming. It includes hardware and software preparation, wiring instructions, sample code, and operation results, enabling users to perform calculations and display results using the micro:bit LED matrix. Ideal for educational projects and DIY enthusiasts looking to enhance their coding skills and explore micro:bit functionalities.
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: https://github.com/DFRobot/pxt-Math-Automatic.
About how to install a software library?
Wiring Diagram
No specific wiring required.
Other Preparation Work
Install the Makecode library from https://github.com/DFRobot/pxt-Math-Automatic.
About how to install a software library?
Sample Code

Math Calculator Example Code Download: https://makecode.microbit.org/_4H0VEYTuo0hA
Result
Use the expansion board as a calculator to do math calculation. Press the key to input the data, and the related RGB will light up, which represents you successfully input the number. The input number will be displayed on the micro:bit LED panel. After the key"=" is pressed, the program will judge which operator you have input first, and then do the math calculation. The result will be circularly displayed on the micro:bit LED matrix for 4 times, waiting for the next calculation.
Was this article helpful?
