problem with led matrix

hi, first off im not very good at coding. i wrote some code for scrolling text over 2 8x8 led matrix with 2 max 7219 chained. the problem is, that the sketch is too big to upload already and im planning to use a third matrix eventually. so the code will get even bigger. besides it seems to me as if there should be an easier way to enter the things to be displayed. maybe someone can help me out with this code or can provide a better solution. here s the code:

#include “LedControl.h”

LedControl lc=LedControl(12,11,10,2);
int delaytime =35;

void setup() {
for(int index=0;index<lc.getDeviceCount();index++) {
lc.shutdown(index,false);

lc.setIntensity(0, 15);
lc.setIntensity(1, 15);
}
}

void loop (){

abc();
}

void abc() {

byte arrow[8]={B00011000,B00100100,B01000010,B10000001,B00011000,B00100100,B01000010,B10000001};
byte space[5]={B00000000,B00000000,B00000000,B00000000,B00000000};

byte a[5]={B01111100,B00010010,B00010010,B01111100,B00000000};
byte b[5]={B01111110,B01001010,B01001010,B00110100,B00000000};
byte c[5]={B00111100,B01000010,B01000010,B00100100,B00000000};
byte d[5]={B01111110,B01000010,B01000010,B00111100,B00000000};
byte e[5]={B01111110,B01001010,B01001010,B01001010,B00000000};
byte f[5]={B01111110,B00001010,B00001010,B00001010,B00000000};
byte g[5]={B00111100,B01000010,B01010010,B00110100,B00000000};
byte h[5]={B01111110,B00010000,B00010000,B01111110,B00000000};
byte ii[3]={B00000000,B01111110,B00000000};
byte j[5]={B00111110,B01000000,B01000000,B00110000,B00000000};
byte k[5]={B01111110,B00010000,B00010000,B01101110,B00000000};
byte l[5]={B01111110,B01000000,B01000000,B01000000,B00000000};
byte m[6]={B01111110,B00000010,B00000110,B00000010,B01111110,B00000000};
byte n[5]={B01111110,B00010000,B00001000,B01111110,B00000000};
byte o[5]={B00111100,B01000010,B01000010,B00111100,B00000000};
byte p[5]={B01111110,B00001010,B00001010,B00000100,B00000000};
byte q[5]={B00111100,B01000010,B01010010,B00111100,B00000100};
byte r[5]={B01111110,B00001010,B00001010,B01110100,B00000000};
byte s[5]={B00100100,B01010010,B01010010,B00101100,B00000000};
byte t[4]={B00000010,B01111110,B00000010,B00000000};
byte u[5]={B00111110,B01000000,B01000000,B00111110,B00000000};
byte v[6]={B00011110,B00100000,B01000000,B00100000,B00111110,B00000000};
byte w[6]={B01111110,B01000000,B01100000,B01000000,B01111110,B00000000};
byte x[6]={B01001110,B00101000,B00010000,B00101000,B01001110,B00000000};
byte y[6]={B00001110,B00001000,B01110000,B00001000,B00001110,B00000000};
byte z[5]={B01000010,B01100010,B01010010,B01001110,B00000000};

for(int i =0;i<70;i++){

lc.setColumn(0,i,a[0]);
lc.setColumn(0,i-1,a[1]);
lc.setColumn(0,i-2,a[2]);
lc.setColumn(0,i-3,a[3]);
lc.setColumn(0,i-4,a[4]);

lc.setColumn(0,i-5,b[0]);
lc.setColumn(0,i-6,b[1]);
lc.setColumn(0,i-7,b[2]);
lc.setColumn(0,i-8,b[3]);
lc.setColumn(0,i-9,b[4]);

lc.setColumn(0,i-10,c[0]);
lc.setColumn(0,i-11,c[1]);
lc.setColumn(0,i-12,c[2]);
lc.setColumn(0,i-13,c[3]);
lc.setColumn(0,i-14,c[4]);

lc.setColumn(0,i-15,d[0]);
lc.setColumn(0,i-16,d[1]);
lc.setColumn(0,i-17,d[2]);
lc.setColumn(0,i-18,d[3]);
lc.setColumn(0,i-19,d[4]);

lc.setColumn(0,i-20,e[0]);
lc.setColumn(0,i-21,e[1]);
lc.setColumn(0,i-22,e[2]);
lc.setColumn(0,i-23,e[3]);
lc.setColumn(0,i-24,e[4]);

lc.setColumn(0,i-25,f[0]);
lc.setColumn(0,i-26,f[1]);
lc.setColumn(0,i-27,f[2]);
lc.setColumn(0,i-28,f[3]);
lc.setColumn(0,i-29,f[4]);

lc.setColumn(0,i-30,g[0]);
lc.setColumn(0,i-31,g[1]);
lc.setColumn(0,i-32,g[2]);
lc.setColumn(0,i-33,g[3]);
lc.setColumn(0,i-34,g[4]);

lc.setColumn(0,i-35,h[0]);
lc.setColumn(0,i-36,h[1]);
lc.setColumn(0,i-37,h[2]);
lc.setColumn(0,i-38,h[3]);
lc.setColumn(0,i-39,h[4]);

lc.setColumn(0,i-40,ii[0]);
lc.setColumn(0,i-41,ii[1]);
lc.setColumn(0,i-42,ii[2]);

lc.setColumn(0,i-43,j[0]);
lc.setColumn(0,i-44,j[1]);
lc.setColumn(0,i-45,j[2]);
lc.setColumn(0,i-46,j[3]);
lc.setColumn(0,i-47,j[4]);

lc.setColumn(0,i-48,k[0]);
lc.setColumn(0,i-49,k[1]);
lc.setColumn(0,i-50,k[2]);
lc.setColumn(0,i-51,k[3]);
lc.setColumn(0,i-52,k[4]);

lc.setColumn(0,i-53,l[0]);
lc.setColumn(0,i-54,l[1]);
lc.setColumn(0,i-55,l[2]);
lc.setColumn(0,i-56,l[3]);
lc.setColumn(0,i-57,l[4]);

lc.setColumn(0,i-58,m[0]);
lc.setColumn(0,i-59,m[1]);
lc.setColumn(0,i-60,m[2]);
lc.setColumn(0,i-61,m[3]);
lc.setColumn(0,i-62,m[4]);
lc.setColumn(0,i-63,m[5]);

lc.setColumn(0,i-64,n[0]);
lc.setColumn(0,i-65,n[1]);
lc.setColumn(0,i-66,n[2]);
lc.setColumn(0,i-67,n[3]);
lc.setColumn(0,i-68,n[4]);

lc.setColumn(0,i-69,o[0]);
lc.setColumn(0,i-70,o[1]);
lc.setColumn(0,i-71,o[2]);
lc.setColumn(0,i-72,o[3]);
lc.setColumn(0,i-73,o[4]);

lc.setColumn(0,i-74,p[0]);
lc.setColumn(0,i-75,p[1]);
lc.setColumn(0,i-76,p[2]);
lc.setColumn(0,i-77,p[3]);
lc.setColumn(0,i-78,p[4]);

lc.setColumn(0,i-79,q[0]);
lc.setColumn(0,i-80,q[1]);
lc.setColumn(0,i-81,q[2]);
lc.setColumn(0,i-82,q[3]);
lc.setColumn(0,i-83,q[4]);

lc.setColumn(0,i-84,r[0]);
lc.setColumn(0,i-85,r[1]);
lc.setColumn(0,i-86,r[2]);
lc.setColumn(0,i-87,r[3]);
lc.setColumn(0,i-88,r[4]);

// delay(delaytime);

// delay(delaytime);

lc.setColumn(1,i-7,a[0]);
lc.setColumn(1,i-8,a[1]);
lc.setColumn(1,i-9,a[2]);
lc.setColumn(1,i-10,a[3]);
lc.setColumn(1,i-11,a[4]);

// delay(delaytime);
lc.setColumn(1,i-12,b[0]);
lc.setColumn(1,i-13,b[1]);
lc.setColumn(1,i-14,b[2]);
lc.setColumn(1,i-15,b[3]);
lc.setColumn(1,i-16,b[4]);

lc.setColumn(1,i-17,c[0]);
lc.setColumn(1,i-18,c[1]);
lc.setColumn(1,i-19,c[2]);
lc.setColumn(1,i-20,c[3]);
lc.setColumn(1,i-21,c[4]);

lc.setColumn(1,i-22,d[0]);
lc.setColumn(1,i-23,d[1]);
lc.setColumn(1,i-24,d[2]);
lc.setColumn(1,i-25,d[3]);
lc.setColumn(1,i-26,d[4]);

lc.setColumn(1,i-27,e[0]);
lc.setColumn(1,i-28,e[1]);
lc.setColumn(1,i-29,e[2]);
lc.setColumn(1,i-30,e[3]);
lc.setColumn(1,i-31,e[4]);

lc.setColumn(1,i-31,f[0]);
lc.setColumn(1,i-32,f[1]);
lc.setColumn(1,i-33,f[2]);
lc.setColumn(1,i-34,f[3]);
lc.setColumn(1,i-35,f[4]);

lc.setColumn(1,i-36,g[0]);
lc.setColumn(1,i-37,g[1]);
lc.setColumn(1,i-38,g[2]);
lc.setColumn(1,i-39,g[3]);
lc.setColumn(1,i-40,g[4]);

lc.setColumn(1,i-41,h[0]);
lc.setColumn(1,i-42,h[1]);
lc.setColumn(1,i-43,h[2]);
lc.setColumn(1,i-44,h[3]);
lc.setColumn(1,i-45,h[4]);

lc.setColumn(1,i-46,ii[0]);
lc.setColumn(1,i-47,ii[1]);
lc.setColumn(1,i-48,ii[2]);

lc.setColumn(1,i-49,j[0]);
lc.setColumn(1,i-50,j[1]);
lc.setColumn(1,i-51,j[2]);
lc.setColumn(1,i-52,j[3]);
lc.setColumn(1,i-53,j[4]);

lc.setColumn(1,i-54,k[0]);
lc.setColumn(1,i-55,k[1]);
lc.setColumn(1,i-56,k[2]);
lc.setColumn(1,i-57,k[3]);
lc.setColumn(1,i-58,k[4]);

lc.setColumn(1,i-59,l[0]);
lc.setColumn(1,i-60,l[1]);
lc.setColumn(1,i-61,l[2]);
lc.setColumn(1,i-62,l[3]);
lc.setColumn(1,i-63,l[4]);

lc.setColumn(1,i-64,m[0]);
lc.setColumn(1,i-65,m[1]);
lc.setColumn(1,i-66,m[2]);
lc.setColumn(1,i-67,m[3]);
lc.setColumn(1,i-68,m[4]);
lc.setColumn(1,i-69,m[5]);

lc.setColumn(1,i-70,n[0]);
lc.setColumn(1,i-71,n[1]);
lc.setColumn(1,i-72,n[2]);
lc.setColumn(1,i-73,n[3]);
lc.setColumn(1,i-74,n[4]);

lc.setColumn(1,i-75,o[0]);
lc.setColumn(1,i-76,o[1]);
lc.setColumn(1,i-77,o[2]);
lc.setColumn(1,i-78,o[3]);
lc.setColumn(1,i-79,o[4]);

lc.setColumn(1,i-80,p[0]);
lc.setColumn(1,i-81,p[1]);
lc.setColumn(1,i-82,p[2]);
lc.setColumn(1,i-83,p[3]);
lc.setColumn(1,i-84,p[4]);

lc.setColumn(1,i-85,q[0]);
lc.setColumn(1,i-86,q[1]);
lc.setColumn(1,i-87,q[2]);
lc.setColumn(1,i-88,q[3]);
lc.setColumn(1,i-89,q[4]);

lc.setColumn(1,i-90,r[0]);
lc.setColumn(1,i-91,r[1]);
lc.setColumn(1,i-92,r[2]);
lc.setColumn(1,i-93,r[3]);
lc.setColumn(1,i-94,r[4]);

delay(delaytime);
}

}

melvin

You should break your code in functions. One main loop that iterate through the message and one function that copy the bitmap to the display. Doing this it will be easier to code and modify your program and it will be 10 times more compact. The table for the bitmap should be put in a 2 dimensions array so that it can be indexed with the character code. As you are not using a fixed font, for each character adding one element in the array to keep the length of the bitmap could be a good idea so that the function in charge of the copy will know how many byte to copy.

hi. thanks for the quick reply. i worked on the code all day, with no succes, just got worse. cant figure out how to write it so it works and is smaller. would it make sense to write some of the code in another tab?

Hint, where you have lines of code that differ by only a constant, make that constant into a variable and put it in a loop with the variable as the loop index. Then you only have one line of code not lots.

you can use sprite instead and you can have scrolling too. See my video and use the code. But (always there is a but) the bigger the matrix the smaller the speed gets. i used 3 8x8 hand made matrix that i build and for the result that you will see in my video i didn't even use one delay. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1229081077

p.s my matrix showing Greek letters but you can modify the code to every language you want by changing the B00010100 you see in code.

hi mikorf, thanks for the code, but i have the same problem concerning size of the sketch with it. i found this LED GRID sketch here: http://ericlathrop.com/electronics/LedGrid.php actually it works the way i want mine to work just that it doesnt use a max72xx. i can display a lot of text with it without the sketch being too big, but only on one 8x8 matrix and using 16 pins on the arduino. another question i have is why that sketch is smaller than mine eventhough it has a lot more text.

nobody have an idea? i m still stuck.

melvin,

I don't know if this will help or not, but with a similar project, I stored my "font" in EEPROM and then wrote functions to access it from the running sketch.

Since the font was loaded with a separate sketch, it did not affect the memory of the working sketch.

I used a separate I2C EEPROM for this, but it may be possible to do with the ATMega's internal EEPROM. (Check out the Playground for both methods.)

There is also "progmem" which may be another way, but I can't comment on that.

Keep trying :) - you will no longer be "not very good at coding" after you succeed.

What does your code currently look like? The last time we saw it seems to have been several sets of modifications ago.

Here’s come code from another project that draws characters from a font given a basic “draw point” function. It might be easier to adapt?
(this uses “progmem” for the font table. A fun

const int font_count = 47;
unsigned char PROGMEM myfont[47][5] = {
  {0, 0, 0, 0, 0}, // space!
  {0x3f, 0x48, 0x48, 0x48, 0x3f}, // A
  {0x7f, 0x49, 0x49, 0x49, 0x36},
  {0x3e, 0x41, 0x41, 0x41, 0x22},
  {0x7f, 0x41, 0x41, 0x22, 0x1c},
   // etc
};

/*
 * Copy a character glyph from the myfont data structure to
 * display memory, with its upper left at the given coordinate
 * This is unoptimized and simply uses plot() to draw each dot.
 */
void ht1632_putchar(byte x, byte y, char c)
{
  byte dots;
  if (c >= 'A' && c <= 'Z' ||
    (c >= 'a' && c <= 'z') ) {
    c &= 0x1F;   // A-Z maps to 1-26
  } 
  else if (c >= '0' && c <= '9') {
    c = (c - '0') + 27;
  } 
  else if (c == ' ') {
    c = 0; // space
  }
  for (char col=0; col< 5; col++) {
    dots = pgm_read_byte_near(&myfont[c][col]);
    for (char row=0; row < 7; row++) {
      if (dots & (64>>row))              // only 7 rows.
        plot(x+col, y+row, 1);
      else 
        plot(x+col, y+row, 0);
    }
  }
}

/*
 * demo_chars
 * draw some characters on the display and scroll them vertically.
 */
void demo_chars ()
{
  cls();

  for (char y=0; y <= Y_MAX-7; y++) {
    ht1632_putchar(0, y, 'A');
    ht1632_putchar(6, y, 'B');
    ht1632_putchar(12, y, '1');
    ht1632_putchar(18, y, '3');
    delay(DISPDELAY);
  }
  delay(LONGDELAY*5);
}

hi, unfortunately i didnt have the time to work on the code till now and i wont before may. so no news here. i ll let you know when that changes. m