BASIC for the micro:bit V2

A couple of years ago I looked into doing a port for the microbit v2 as I had already done one for the first version.

Well finally completed that today. Benchmarks have been added to the table

A Blinky demo in BASIC and the source below

Still working on getting the release together, but that should be ready soon.

This is what testing sometimes looks like, not pretty, but effective.

' For micro:bit v2 (nRF52833)
' Light each of the 25 LEDs in turn — equivalent to the original
' MicroBit display.bas, but for the simpler 5x5 matrix on v2 hardware.
'
' Rows (anodes, drive HIGH to enable):  P0.21, P0.22, P0.15, P0.24, P0.19
' Cols (cathodes, drive LOW to light):  P0.28, P0.11, P0.31, P1.05, P0.30
'
' Coridium Corp, 2026, may be used with this notice.

#include <NRF52833.bas>            ' holds definitions for hardware registers, not needed in this example

' P1.x pins are addressed as 32+x in BASIC's out()/output()
#define ROW1   21
#define ROW2   22
#define ROW3   15
#define ROW4   24
#define ROW5   19
#define COL1   28
#define COL2   11
#define COL3   31
#define COL4   (32+5)      ' P1.05
#define COL5   30

const ROWS as byte = { ROW1, ROW2, ROW3, ROW4, ROW5 }
const COLS as byte = { COL1, COL2, COL3, COL4, COL5 }

SUB blink(x, y, t)
    dim r, c
    r = ROWS(y)
    c = COLS(x)

    out(c) = 0       ' col LOW  -> sink current
    out(r) = 1       ' row HIGH -> source current = LED on
    wait(t)
    out(r) = 0       ' row LOW  -> LED off
    out(c) = 1       ' col HIGH -> idle
END SUB

MAIN:

print "micro:bit v2 LED matrix demo"

dim i, x, y

' Configure all row and column pins as outputs
for i = 0 to 4
    output(ROWS(i))
    output(COLS(i))
next i

' Idle state: rows low (off), cols high (off)
for i = 0 to 4
    out(ROWS(i)) = 0
    out(COLS(i)) = 1
next i

' Sweep each pixel
while 1
    for y = 0 to 4
        for x = 0 to 4
            blink(x, y, 100)
        next x
    next y
loop

Previous Post