Here's some code that lets you specify an 8x8 matrix of individual pixels, then combines all the pixels in a row into the one number that will get passed to max7219_put (I'm calling the array of those 8 numbers a sprite).
Displaying multiple sprites on the LED display at once will be a bit trickier. Do you want them to scroll horizontally, vertically or both? (Both is much more complicated, as potentially parts of 4 letters could be shown at once, and you need a two-dimensional array of text).
I'm thinking that all of this should get added to the display library at some point, so that your code will become much simpler. If you have a sense of other things you'd like to do with the display, let us know, as it will help plan the library.
[code] boolean arrow_pixels[8][8] = { {0, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 1, 1, 0, 0}, {0, 0, 1, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 1} }; int arrow[8]; int frame = 0;
void createSprite(int pixels[8][8], int sprite[8]) { int row, col;
for (row = 0; row < 8; row++) { sprite[row] = 0;
for (col = 0; col < 8; col++) { sprite[row] += pixels[row][col] << (col ? col - 1 : 7); } } }
// draws arrow on 8x8 led matrix w/ vertical offset of 0-7 inclusive (wraps) void drawSprite(int sprite[8], int voffset) { int row;
for (row = 0; row < 8; row++) { max7219_put(row + 1, sprite[(row + voffset) % 8]); } }
void setup() { createSprite(arrow_pixels, arrow); }
void loop() { drawSprite(arrow, frame); delay(100); frame++; } [/code]
IP Logged
|