LED matrix 2: software


The software was refined in a few iterations. I started from the software referenced in the Instructable on the starting page of this project. This code was used to test the LED matrix, and to learn how the low-level SPI interface works on the Arduino. From there on, I started developing my own code to handle bitmaps and text in a more elegant way.

The software is a work in progress, but it already evolved into a library that can be included in a sketch, and provide the display functionality without much other hassle. The source code for the LEDMatrix library is here:

Arduino libraries

Download the files from the “LEDMatrix” subdirectory to a “LEDMatrix” subdirectory in your Arduino IDEs “libraries” folder, and you have instant access to the code by #include-ing “ledmatrix.h”.

The library has 3 files: letters.h, ledmatrix.h and ledmatrix.cpp. letters.h holds the character definitions that make up the font; they can easily be modified or substituted with another file. The crucial point is the names of the arrays; ledmatrix.cpp maps from actual characters to the character bitmap arrays in the setChar function.

ledmatrix.cpp has 3 “code layers”:

  • the high-level interface functions that are called from the main loop.
  • the middle-level functions that handle the transformation from text to bitmap and projection of bitmaps onto the display buffer.
  • the low-level SPI interface code, that sends the display buffer contents to the controller.

An example of code that uses the library is shown below. This is the code that was used to make the video on the starting page of this project.

#include <ledmatrix.h>

LEDMatrix ledMatrix;

byte bitmapExample[6][24] = 
   { { 0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0 },
     { 0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0 },
     { 0,1,1,0,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,1,1,0 },
     { 1,0,0,1,0,0,1,0,0,1,0,1,1,0,1,0,0,1,0,0,1,0,0,1 },
     { 0,0,0,0,1,1,0,0,0,1,0,0,0,0,1,0,0,0,1,1,0,0,0,0 },
     { 0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0 } };

void setup() {

void loop() {
  ledMatrix.showStatic(bitmapExample, 6, 600);
  ledMatrix.scrollVertical(bitmapExample, 6);

  ledMatrix.prepareText("jvl 2015");