the LED matrix is a 25-LED multiplexed array. You can't just set the LED's on or off, they must be scanned through continuously to keep them lit. To make this easy for you we've added support to the Adafruit_Microbit library - it even uses a timer (Timer 2) to manage all the multiplexing for you.
First up, install the Adafruit helper libraries
Open up the matrixdemo sketch and upload it to your bit
The library manages all the refreshing, the drawing routines are all handled by Adafruit_GFX which we have documented in detail here https://learn.adafruit.com/adafruit-gfx-graphics-library/
Note that the screen is small so even though the GFX library can do a lot, there's not a ton of space for complex shapes. We do have a small and simple font you can use that will fit in the 5-pixel-tall display, called TomThumb.h
We've overloaded the print function so you can use that to print scrolling text:
// scroll some text the 'easy' way microbit.print("HELLO WORLD");
or even numbers and floating points
// count up! for (int i=0; i<10; i++) { microbit.print(i); delay(500); } microbit.print(3.1415, 4); // pi time, 4 digits of precision!!
Note that for single-digits or single-char print()
's you wont get scrolling text.
For bitmaps, the screen is 5x5 but to make the math easier on everyone, you can store bitmaps in 8-bit-wide structures and just ignore the left-most 3 bits in each 8-bit word:
const uint8_t smile_bmp[] = { B00000, B01010, B00000, B10001, B01110, };
We also have a range of built in images you can use here at the bottom.
You can draw bitmaps with show()
- pass in either one of the built in microbit.BITMAP
's or your own custom bitmap
// draw a heart microbit.show(microbit.HEART); delay(1000); // draw a no cross microbit.show(microbit.NO); delay(1000); // draw a yes check microbit.show(microbit.YES); delay(1000); // draw a custom made bitmap face microbit.show(smile_bmp); delay(1000);