2 * LED Matrix library for http://www.seeedstudio.com/depot/ultrathin-16x32-red-led-matrix-panel-p-1582.html
3 * The LED Matrix panel has 32x16 pixels. Several panel can be combined together as a large screen.
5 * Coordinate & Connection (Arduino -> panel 0 -> panel 1 -> ...)
7 * +--------+--------+--------+ +--------+--------+
8 * | 5 | 4 | 3 | | 1 | 0 |
9 * | | | | | | |<----- Arduino
10 * +--------+--------+--------+ +--------+--------+
11 * | 2 | 1 | 0 | (64, 16)
12 * | | | |<----- Arduino
13 * +--------+--------+--------+
20 #include <avr/pgmspace.h>
21 #include "LEDMatrix.h"
24 #define WIDTH 64*1 // 2 panels * 64
28 #include <SPI.h> // Arduino IDE compilation won't work without this
31 // hub08 pinout: la lb lc ld en r1 lat clk
32 // LEDMatrix(a, b, c, d, oe, r1, stb, clk);
33 LEDMatrix matrix(4, 5, 6, 7, 9, 11, 10, 13);
35 // Display Buffer 128 = 64 * 16 / 8
36 uint8_t displaybuf[(WIDTH/8) * HEIGHT*2];
38 uint8_t displaybuf_w[((WIDTH/8)+1) * HEIGHT];
42 void MatrixWriteCharacter(int x,int y, char character)
46 //Serial.println(character);
48 for(int i=0; i<8; i++) {
49 uint8_t *pDst = displaybuf_w + (i+y) * ((WIDTH / 8) + 1) + x ;
50 *pDst = (font_8x8[character - 0x20][i]);
53 for(int i=0; i<16; i++) {
54 cell[i] = pgm_read_byte_near(&font_8x16[(character - 0x20)][i]);
57 //uint8_t *pDst = displaybuf_w + (y) * ((WIDTH / 8) + 1) + x ;
58 uint8_t *pDst = displaybuf_w + x + y * ((WIDTH/8)+1);
61 for(int j=0; j<8; j++) {
64 for(int i=0; i<8; i++) {
66 if ( cell[i] & mask ) {
77 for(int j=0; j<8; j++) {
79 for(int i=8; i<16; i++) {
81 if ( cell[i] & mask ) {
95 void matrixPrint(String c) {
98 //Serial.println(c.length());
99 for (int i=0 ; i<c.length() ; i++) {
100 MatrixWriteCharacter(i,3,c[i]);
103 //Serial.print(" -> ");
104 //Serial.println(c[i]);
111 matrix.begin(displaybuf, WIDTH, HEIGHT);
112 Serial.begin(115200);
114 //matrixPrint("12345678");
115 // uint8_t *pDst = displaybuf + y * (WIDTH / 8) + x / 8;
116 memset(displaybuf_w, 0, sizeof(displaybuf_w));
119 void matrixDelay(int x) {
120 for (int y=0; y<x; y++) { matrix.scan(); }
124 //String poruka="X XX XOX XOOX XOoOX XOooOX XOoIoOX XOoiioOX ";
125 //String poruka=" Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras blandit libero id ex dapibus suscipit. Proin vitae cursus eros. Ut porttitor congue metus at viverra. In consectetur ex massa.";
126 String poruka="!\"#$%&'()*+,-./0123456789:;<=>?@AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqReSsTtUuVvWwXxYyZz[\\]^_`{|}~";
129 int pos = 0; // position in circular display
133 for (int p=0; p<poruka.length() ; p++) {
134 pos = ( pos + 1 ) % (( WIDTH / 8 )+1);
135 // int pos_ch = ( pos + (WIDTH/8) ) % (( WIDTH / 8 )+1);
136 int pos_ch = ( pos + (WIDTH/8) ) % (( WIDTH / 8 )+1);
137 MatrixWriteCharacter(pos_ch,0,poruka.charAt(p));
139 int step_up = ((WIDTH/8)+1)-pos; // move up one line when falling off the end of circular buffer
142 Serial.print(" step_up=");
143 Serial.print(step_up);
144 Serial.print(" char=");
145 Serial.println(poruka.charAt(p));
147 for (int o=0; o<8; o++) {
148 uint8_t *src = displaybuf_w + pos;
149 uint8_t *dest = matrix.offscreen_buffer();
153 for (int y = 0; y < HEIGHT; y++ ) {
154 for (int x = 0; x < (WIDTH/8); x++) {
156 int j = ( x < step_up ? y : y-1 ) * ((WIDTH/8)+1) + x;
157 int j1 = ( x+1 < step_up ? y : y-1 ) * ((WIDTH/8)+1) + x+1;
159 *(dest + i) = ( *(src + j) << o ) | (( *(src + j1) & ( 0xff << 8 - o ) ) >> 8 - o );
160 // *(dest + i) = *(src + j);
163 delayMicroseconds(100 / (WIDTH / 64));
166 delayMicroseconds(100 / (WIDTH / 64));