Pages: [1]   Go Down
Author Topic: Fast Buffer Based LedMatrix Library with Drawing, Scrolling and Sprite support.  (Read 979 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just finished version 0.07 of my fast buffer based led matrix library for Max7219 based led matrix hardware that has the following features:

1. basic Max7219 operations -- setting intensity, shutting down, etc
2. It only operates in non-decode mode of Max7219, so all are graphics
3. line drawing
4. circle drawing
5. rectangle drawing
6. get and set pixel
7. scrolling both vertically and horizontally
8. 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

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 - downloaded 9 times.)
« Last Edit: February 07, 2013, 11:29:03 am by mjkzz » Logged

Search for "mjkzz" on eBay :-)

Offline Offline
Full Member
***
Karma: 1
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Demostration Video -- the speed is limited by how fast the IR remote can send IR signals . . .

http://player.youku.com/player.php/sid/XNTEyNTYzMDQw/v.swf
Logged

Search for "mjkzz" on eBay :-)

Offline Offline
Full Member
***
Karma: 1
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Library is available on github . . .

https://github.com/mjkzz/LedMatrix

Anyone knows how to edit and update Arduino Playground? Thanks.
Logged

Search for "mjkzz" on eBay :-)

Pages: [1]   Go Up
Jump to: