Just finished version 0.07 of my fast buffer based led matrix library for Max7219 based led matrix hardware that has the following features:
- basic Max7219 operations -- setting intensity, shutting down, etc
- It only operates in non-decode mode of Max7219, so all are graphics
- line drawing
- circle drawing
- rectangle drawing
- get and set pixel
- scrolling both vertically and horizontally
- bitmapped sprite drawing support
In particular, the sprite drawing and scrolling are pretty fast because all drawing operations are done in memory and then with one single hardware update.
Sample code
#include <avr/io.h>
#include <avr/interrupt.h>
#include "LedMatrix.h"
//
// create a LedMatrix object for two 8x8 led matrix
// cascaded horizontally
//
// SPI pins
//
// DIN = 2
// CS/LOAd = 3
// CLK = 4
//
// Display info
//
// WIDTH = 16
// HEIGHT = 8
//
LedMatrix lm(2, 3, 4, 16, 8);
char x = 0;
char y = 0;
//
// This is a bitmap for a sprite
// The first two bytes specify width and height of
// sprite and the rest are bitmaps for sprite
//
byte g_sprite[6] =
{
0x03, // width
0x04, // height
0b10110000,
0b01001000,
0b01000100,
0b10100010,
};
void setup()
{
Serial.begin(115200);
Serial.println("Start . . .");
// initialize and start LedMatrix with intensity of 0x08
lm.init(0x08);
// blank out the display
lm.blank();
//lm.line(15, 7, 0, 0, GRAPHIC_DRAW_SRC);
lm.sprite(x, y, (const char *)g_sprite, 6, GRAPHIC_DRAW_SRC);
//lm.circle(4, 4, 2, GRAPHIC_DRAW_SRC);
// after finishing all drawing in memory, put it out to hardware
lm.update();
delay(3000);
}
void loop()
{
// LedMatrix lib supports XOR on sprite
// erase previously drawn sprite using XOR
lm.sprite(x, y, (const char *)g_sprite, 6, GRAPHIC_DRAW_XOR);
// move it around
if (x < lm.getWidth()-1)
{
x+=1;
}
else
{
x = 0;
if (y < lm.getHeight()-1)
{
y+=1;
}
else
{
y = 0;
}
}
// draw the sprite at new location after moving it around
lm.sprite(x, y, (const char *)g_sprite, 6, GRAPHIC_DRAW_SRC);
// update hardware
lm.update();
delay(200);
}
It is started and written for the hardware that I designed that support seamless cascade of Max7219 modules:
http://www.ebay.com/itm/281055201039?ssPageName=STRK:MESELX:IT&_trksid=p3984.m1555.l2649
However, it will also work with hardware that are designed to work with LedControl library.
LedMatrix.zip (4.95 KB)