Example Code for micro:bit-Comparing Number
Last revision 2025/12/31
This article provides a comprehensive guide on using micro:bit for comparing numbers, featuring detailed hardware and software preparations, including installation of the Makecode library, and sample code that allows users to interactively display results on an LED panel based on random number comparisons.
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.
Other Preparation Work
Install the Makecode library from https://github.com/DFRobot/pxt-Math-Automatic.
About how to install a software library?
Sample Code

Comparing Number Example Code Download
Result
Press down button A on micro:bit, a countdown will appear on micro:bit LED panel, and it shows a random number; Touch the DFlogo key, the RGB LEDs 0~9 "jump" randomly and then generates a random number. Compare the two numbers. If the former one is bigger, micro:bit LED displays a left arrow; if the latter one is bigger, display a right arrow; if equal, display a "heart" pattern. Random number range: 0~9.
Was this article helpful?
