README | TH-README
A MakeCode extension for the micro:bit that displays numbers on the 5×5 LED matrix in 2 of 5 style.
Inspired by the 2 of 5 barcode family, especially Interleaved 2 of 5 (ITF).
Demo:
- 2of5 stopwatch
- 2of5 password (demo of
write2of5)Project page: https://quarequin.github.io/microbit-2of5-font/
- Render numbers in classic 2 of 5 patterns on the 5×5 screen
- Support for negative numbers (shown via inverted dots)
- Optional Guard mode (uses the 6th digit as invert reference)
- Optional Transpose mode (swap vertical ↔ horizontal)
- Optional Brightness control (0–255)
- Single-digit display or dual-number display with alignment
write2of5helper — maps two bit positions back to a digit (uses binary search)- Very compact implementation using a single
Bufferfor all 2 of 5 patterns
- Open https://makecode.microbit.org/
- Create a New Project
- Click the gear icon → Extensions
- Paste this URL and import:
https://github.com/Quarequin/microbit-2of5-font
(The previous URL https://github.com/phatisena/microbit-2of5-font still works.)
| Function | Description |
|---|---|
write2of5(a, b) |
Map two bit positions (0–4) to a 2of5 digit (returns -1 if invalid) |
show2of5Number(n, guard, transpose?, brightness?) |
Show a full number (up to 5 or 6 digits) |
show2of5SingleNumber(n, col, inv, transpose?, brightness?) |
Show a single digit at a specific column |
show2of5DualNumber(a, b, align, transpose?, brightness?) |
Show two numbers side-by-side (Left / Center / Right) |
- guard — when
true, the 6th digit controls invert of each digit - transpose — rotate the display (vertical ↔ horizontal)
- brightness — LED brightness level (0–255, default 255)
- inv — invert the dots of that digit (also used for negative numbers)
- align —
Left/Center/Rightfor dual mode - a, b (in
write2of5) — bit positions (0–4). Must be different.
Each digit is encoded with 5 bits (exactly two bits set to 1):
0 → 11000
1 → 10100
2 → 10010
3 → 10001
4 → 01100
5 → 01010
6 → 01001
7 → 00110
8 → 00101
9 → 00011
Stored as a compact descending Buffer (the “2of5 magic buffer”):
const pin2of5: Buffer = hex`181412110C0A09060503`write2of5 uses binary search on this buffer to convert two bit positions back into a digit.
- Open https://makecode.microbit.org/
- Click Import → Import URL
- Paste:
https://github.com/Quarequin/microbit-2of5-font
- Target: micro:bit (MakeCode / PXT)
- Language: TypeScript
- Current version: 6.1.0 (see
pxt.json)
- for PXT/microbit