56x8 led matrix with 7 maxx7221

hi, i have a problem with my code for driving a long led matrix with 7 cascaded maxx7221. it works perfectly for static stuff, but with animated words it gets very slow and the code gets really big for displaying a few words. im using an arduino mega and the code for two words going from left to right takes up about 1/5th of the complete memory. the code works but as i said it gets very slow and its probably written too complicated. took me a few days to get it running
here s the code:

  #include "LedControl.h"

  LedControl lc=LedControl(12,11,10,7); 


 
  byte a[8]={B00000000,B10011100,B00101000,B01001000,B01001000,B00101000,B10011100,B00000000};
  byte k[8]={B00000000,B11111100,B00100000,B00100000,B00100000,B00100000,B11011100,B00000000};
  byte n[8]={B00000000,B11111100,B01000000,B00100000,B00010000,B00001000,B11111100,B00000000};
  byte p[8]={B00000000,B11111100,B10010000,B10010000,B10010000,B10010000,B01100000,B00000000};
  byte s[8]={B00000000,B01001000,B10100100,B10100100,B10100100,B10100100,B00011000,B00000000};

  

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

    lc.setIntensity(index, 15);
 

 

    }
  }

  void loop (){





     for(int i=0;i<150;i++){
  
       
//matrix 7
 lc.setColumn(0,i,n[7]);
 lc.setColumn(0,i-1,n[6]);
 lc.setColumn(0,i-2,n[5]);
 lc.setColumn(0,i-3,n[4]);
 lc.setColumn(0,i-4,n[3]);
 lc.setColumn(0,i-5,n[2]);
 lc.setColumn(0,i-6,n[1]);
 lc.setColumn(0,i-7,n[0]);
  
 lc.setColumn(0,i-8,k[7]);
 lc.setColumn(0,i-9,k[6]);
 lc.setColumn(0,i-10,k[5]);
 lc.setColumn(0,i-11,k[4]);
 lc.setColumn(0,i-12,k[3]);
 lc.setColumn(0,i-13,k[2]);
 lc.setColumn(0,i-14,k[1]);
 lc.setColumn(0,i-15,k[0]);  
 
 lc.setColumn(0,i-16,s[7]);
 lc.setColumn(0,i-17,s[6]);
 lc.setColumn(0,i-18,s[5]);
 lc.setColumn(0,i-19,s[4]);
 lc.setColumn(0,i-20,s[3]);
 lc.setColumn(0,i-21,s[2]);
 lc.setColumn(0,i-22,s[1]);
 lc.setColumn(0,i-23,s[0]);
  
 lc.setColumn(0,i-24,p[7]);
 lc.setColumn(0,i-25,p[6]);
 lc.setColumn(0,i-26,p[5]);
 lc.setColumn(0,i-27,p[4]);
 lc.setColumn(0,i-28,p[3]);
 lc.setColumn(0,i-29,p[2]);
 lc.setColumn(0,i-30,p[1]);
 lc.setColumn(0,i-31,p[0]);  

 lc.setColumn(0,i-32,a[7]);
 lc.setColumn(0,i-33,a[6]);
 lc.setColumn(0,i-34,a[5]);
 lc.setColumn(0,i-35,a[4]);
 lc.setColumn(0,i-36,a[3]);
 lc.setColumn(0,i-37,a[2]);
 lc.setColumn(0,i-38,a[1]);
 lc.setColumn(0,i-39,a[0]);  


//matrix 6
 lc.setColumn(1,i-7,n[7]);
 lc.setColumn(1,i-8,n[6]);
 lc.setColumn(1,i-9,n[5]);
 lc.setColumn(1,i-10,n[4]);
 lc.setColumn(1,i-11,n[3]);
 lc.setColumn(1,i-12,n[2]);
 lc.setColumn(1,i-13,n[1]);
 lc.setColumn(1,i-14,n[0]);

 lc.setColumn(1,i-15,k[7]);
 lc.setColumn(1,i-16,k[6]);
 lc.setColumn(1,i-17,k[5]);
 lc.setColumn(1,i-18,k[4]);
 lc.setColumn(1,i-19,k[3]);
 lc.setColumn(1,i-20,k[2]);
 lc.setColumn(1,i-21,k[1]);
 lc.setColumn(1,i-22,k[0]);
 
 lc.setColumn(1,i-23,s[7]);
 lc.setColumn(1,i-24,s[6]);
 lc.setColumn(1,i-25,s[5]);
 lc.setColumn(1,i-26,s[4]);
 lc.setColumn(1,i-27,s[3]);
 lc.setColumn(1,i-28,s[2]);
 lc.setColumn(1,i-29,s[1]);
 lc.setColumn(1,i-30,s[0]);

 lc.setColumn(1,i-31,p[7]);
 lc.setColumn(1,i-32,p[6]);
 lc.setColumn(1,i-33,p[5]);
 lc.setColumn(1,i-34,p[4]);
 lc.setColumn(1,i-35,p[3]);
 lc.setColumn(1,i-36,p[2]);
 lc.setColumn(1,i-37,p[1]);
 lc.setColumn(1,i-38,p[0]);
 
 lc.setColumn(1,i-39,a[7]);
 lc.setColumn(1,i-40,a[6]);
 lc.setColumn(1,i-41,a[5]);
 lc.setColumn(1,i-42,a[4]);
 lc.setColumn(1,i-43,a[3]);
 lc.setColumn(1,i-44,a[2]);
 lc.setColumn(1,i-45,a[1]);
 lc.setColumn(1,i-46,a[0]);


//matrix 5
 lc.setColumn(2,i-14,n[7]);
 lc.setColumn(2,i-15,n[6]);
 lc.setColumn(2,i-16,n[5]);
 lc.setColumn(2,i-17,n[4]);
 lc.setColumn(2,i-18,n[3]);
 lc.setColumn(2,i-19,n[2]);
 lc.setColumn(2,i-20,n[1]);
 lc.setColumn(2,i-21,n[0]);
 
 lc.setColumn(2,i-22,k[7]);
 lc.setColumn(2,i-23,k[6]);
 lc.setColumn(2,i-24,k[5]);
 lc.setColumn(2,i-25,k[4]);
 lc.setColumn(2,i-26,k[3]);
 lc.setColumn(2,i-27,k[2]);
 lc.setColumn(2,i-28,k[1]);
 lc.setColumn(2,i-29,k[0]);
 
 lc.setColumn(2,i-30,s[7]);
 lc.setColumn(2,i-31,s[6]);
 lc.setColumn(2,i-32,s[5]);
 lc.setColumn(2,i-33,s[4]);
 lc.setColumn(2,i-34,s[3]);
 lc.setColumn(2,i-35,s[2]);
 lc.setColumn(2,i-36,s[1]);
 lc.setColumn(2,i-37,s[0]);

 lc.setColumn(2,i-38,p[7]);
 lc.setColumn(2,i-39,p[6]);
 lc.setColumn(2,i-40,p[5]);
 lc.setColumn(2,i-41,p[4]);
 lc.setColumn(2,i-42,p[3]);
 lc.setColumn(2,i-43,p[2]);
 lc.setColumn(2,i-44,p[1]);
 lc.setColumn(2,i-45,p[0]);
 
 lc.setColumn(2,i-46,a[7]);
 lc.setColumn(2,i-47,a[6]);
 lc.setColumn(2,i-48,a[5]);
 lc.setColumn(2,i-49,a[4]);
 lc.setColumn(2,i-50,a[3]);
 lc.setColumn(2,i-51,a[2]);
 lc.setColumn(2,i-52,a[1]);
 lc.setColumn(2,i-53,a[0]);
     
     
 //matrix 4     
 lc.setColumn(3,i-22,n[7]);
 lc.setColumn(3,i-23,n[6]);
 lc.setColumn(3,i-24,n[5]);
 lc.setColumn(3,i-25,n[4]);
 lc.setColumn(3,i-26,n[3]);
 lc.setColumn(3,i-27,n[2]);
 lc.setColumn(3,i-28,n[1]);
 lc.setColumn(3,i-29,n[0]);
 
 lc.setColumn(3,i-30,k[7]);
 lc.setColumn(3,i-31,k[6]);
 lc.setColumn(3,i-32,k[5]);
 lc.setColumn(3,i-33,k[4]);
 lc.setColumn(3,i-34,k[3]);
 lc.setColumn(3,i-35,k[2]);
 lc.setColumn(3,i-36,k[1]);
 lc.setColumn(3,i-37,k[0]);

 lc.setColumn(3,i-38,s[7]);
 lc.setColumn(3,i-39,s[6]);
 lc.setColumn(3,i-40,s[5]);
 lc.setColumn(3,i-41,s[4]);
 lc.setColumn(3,i-42,s[3]);
 lc.setColumn(3,i-43,s[2]);
 lc.setColumn(3,i-44,s[1]);
 lc.setColumn(3,i-45,s[0]);
 
 lc.setColumn(3,i-46,p[7]);
 lc.setColumn(3,i-47,p[6]);
 lc.setColumn(3,i-48,p[5]);
 lc.setColumn(3,i-49,p[4]);
 lc.setColumn(3,i-40,p[3]);
 lc.setColumn(3,i-51,p[2]);
 lc.setColumn(3,i-52,p[1]);
 lc.setColumn(3,i-53,p[0]);
 
 lc.setColumn(3,i-54,a[7]);
 lc.setColumn(3,i-55,a[6]);
 lc.setColumn(3,i-56,a[5]);
 lc.setColumn(3,i-57,a[4]);
 lc.setColumn(3,i-58,a[3]);
 lc.setColumn(3,i-59,a[2]);
 lc.setColumn(3,i-60,a[1]);
 lc.setColumn(3,i-61,a[0]); 


//matrix 3
 lc.setColumn(4,i-29,n[7]);
 lc.setColumn(4,i-30,n[6]);
 lc.setColumn(4,i-31,n[5]);
 lc.setColumn(4,i-32,n[4]);
 lc.setColumn(4,i-33,n[3]);
 lc.setColumn(4,i-34,n[2]);
 lc.setColumn(4,i-35,n[1]);
 lc.setColumn(4,i-36,n[0]);

 lc.setColumn(4,i-37,k[7]);
 lc.setColumn(4,i-38,k[6]);
 lc.setColumn(4,i-39,k[5]);
 lc.setColumn(4,i-40,k[4]);
 lc.setColumn(4,i-41,k[3]);
 lc.setColumn(4,i-42,k[2]);
 lc.setColumn(4,i-43,k[1]);
 lc.setColumn(4,i-44,k[0]);

 lc.setColumn(4,i-45,s[7]);
 lc.setColumn(4,i-46,s[6]);
 lc.setColumn(4,i-47,s[5]);
 lc.setColumn(4,i-48,s[4]);
 lc.setColumn(4,i-49,s[3]);
 lc.setColumn(4,i-50,s[2]);
 lc.setColumn(4,i-51,s[1]);
 lc.setColumn(4,i-52,s[0]);
 
 lc.setColumn(4,i-53,p[7]);
 lc.setColumn(4,i-54,p[6]);
 lc.setColumn(4,i-55,p[5]);
 lc.setColumn(4,i-56,p[4]);
 lc.setColumn(4,i-57,p[3]);
 lc.setColumn(4,i-58,p[2]);
 lc.setColumn(4,i-59,p[1]);
 lc.setColumn(4,i-60,p[0]);
 
 lc.setColumn(4,i-61,a[7]);
 lc.setColumn(4,i-62,a[6]);
 lc.setColumn(4,i-63,a[5]);
 lc.setColumn(4,i-64,a[4]);
 lc.setColumn(4,i-65,a[3]);
 lc.setColumn(4,i-66,a[2]);
 lc.setColumn(4,i-67,a[1]);
 lc.setColumn(4,i-68,a[0]);  
 
 
 //matrix 2
 lc.setColumn(5,i-36,n[7]);
 lc.setColumn(5,i-37,n[6]);
 lc.setColumn(5,i-38,n[5]);
 lc.setColumn(5,i-39,n[4]);
 lc.setColumn(5,i-40,n[3]);
 lc.setColumn(5,i-41,n[2]);
 lc.setColumn(5,i-42,n[1]);
 lc.setColumn(5,i-43,n[0]);

 lc.setColumn(5,i-44,k[7]);
 lc.setColumn(5,i-45,k[6]);
 lc.setColumn(5,i-46,k[5]);
 lc.setColumn(5,i-47,k[4]);
 lc.setColumn(5,i-48,k[3]);
 lc.setColumn(5,i-49,k[2]);
 lc.setColumn(5,i-50,k[1]);
 lc.setColumn(5,i-51,k[0]);

 lc.setColumn(5,i-52,s[7]);
 lc.setColumn(5,i-53,s[6]);
 lc.setColumn(5,i-54,s[5]);
 lc.setColumn(5,i-55,s[4]);
 lc.setColumn(5,i-56,s[3]);
 lc.setColumn(5,i-57,s[2]);
 lc.setColumn(5,i-58,s[1]);
 lc.setColumn(5,i-59,s[0]);
 
 lc.setColumn(5,i-60,p[7]);
 lc.setColumn(5,i-61,p[6]);
 lc.setColumn(5,i-62,p[5]);
 lc.setColumn(5,i-63,p[4]);
 lc.setColumn(5,i-64,p[3]);
 lc.setColumn(5,i-65,p[2]);
 lc.setColumn(5,i-66,p[1]);
 lc.setColumn(5,i-67,p[0]);
 
 lc.setColumn(5,i-68,a[7]);
 lc.setColumn(5,i-69,a[6]);
 lc.setColumn(5,i-70,a[5]);
 lc.setColumn(5,i-71,a[4]);
 lc.setColumn(5,i-72,a[3]);
 lc.setColumn(5,i-73,a[2]);
 lc.setColumn(5,i-74,a[1]);
 lc.setColumn(5,i-75,a[0]);


//matrix 1
 lc.setColumn(6,i-43,n[7]);
 lc.setColumn(6,i-44,n[6]);
 lc.setColumn(6,i-45,n[5]);
 lc.setColumn(6,i-46,n[4]);
 lc.setColumn(6,i-47,n[3]);
 lc.setColumn(6,i-48,n[2]);
 lc.setColumn(6,i-49,n[1]);
 lc.setColumn(6,i-50,n[0]);
 
 lc.setColumn(6,i-51,k[7]);
 lc.setColumn(6,i-52,k[6]);
 lc.setColumn(6,i-53,k[5]);
 lc.setColumn(6,i-54,k[4]);
 lc.setColumn(6,i-55,k[3]);
 lc.setColumn(6,i-56,k[2]);
 lc.setColumn(6,i-57,k[1]);
 lc.setColumn(6,i-58,k[0]);

 lc.setColumn(6,i-59,s[7]);
 lc.setColumn(6,i-60,s[6]);
 lc.setColumn(6,i-61,s[5]);
 lc.setColumn(6,i-62,s[4]);
 lc.setColumn(6,i-63,s[3]);
 lc.setColumn(6,i-64,s[2]);
 lc.setColumn(6,i-65,s[1]);
 lc.setColumn(6,i-66,s[0]);
 
 lc.setColumn(6,i-67,p[7]);
 lc.setColumn(6,i-68,p[6]);
 lc.setColumn(6,i-69,p[5]);
 lc.setColumn(6,i-70,p[4]);
 lc.setColumn(6,i-71,p[3]);
 lc.setColumn(6,i-72,p[2]);
 lc.setColumn(6,i-73,p[1]);
 lc.setColumn(6,i-74,p[0]);
 
 lc.setColumn(6,i-75,a[7]);
 lc.setColumn(6,i-76,a[6]);
 lc.setColumn(6,i-77,a[5]);
 lc.setColumn(6,i-78,a[4]);
 lc.setColumn(6,i-79,a[3]);
 lc.setColumn(6,i-80,a[2]);
 lc.setColumn(6,i-81,a[1]);
 lc.setColumn(6,i-82,a[0]); 
 
  }
}

i couldnt manage to simplify it so it wouldn t have to run through all those lines of code in each loop. if anybody has a tip on how to write it smarter or a different method i would be very happy and grateful. thanks,
garglgar

nobody have a solution for the problem?

I don't know about the slow problem, because the code is sooooo long.

You could shorted it considerably with a few functions. You have code like this:

 lc.setColumn(1,i-31,p[7]);
 lc.setColumn(1,i-32,p[6]);
 lc.setColumn(1,i-33,p[5]);
 lc.setColumn(1,i-34,p[4]);
 lc.setColumn(1,i-35,p[3]);
 lc.setColumn(1,i-36,p[2]);
 lc.setColumn(1,i-37,p[1]);
 lc.setColumn(1,i-38,p[0]);

You could put this code in a function, taking three arguments - the value for position 1, the initial value for position 2, and the array to be accessed for position 3.

void showSomething(byte arg1, byte arg2, byte arg3[])
{
   for(byte i=0, j=7; i<8; i++,j--)
   {
      lcd.setColumn(arg1, arg2+i, arg3[j]);
   }
}

Replace your code above with a call to the function:

showSomething(1, i-31, p);

Figure out what arguments to pass to the function for similar blocks of code.

This will shorten your code considerably. Then, we can concentrate on your other problem(s).

thanks, i ll check it later and let you know how it worked out.

hi. im still stuck. the problem is that cant change all the variables at once like that. if i write it like this:

for(byte i=0, j=0; i<8, j<=7;i++, j++){
 lc.setColumn(0,i,n[j]);
}

the letter is static. the 0 is the matrix i address, the i is the column of that matrix and the array is the column of the letter. it has to be like matrix 0, first column of the letter in the first column of the matrix, then first column of the letter in in the second column of the matrix and the second column of the letter in the first column of the matrix and so on up to the last column. when the first column of the letter passed the last column of the first matrix the same thing has to start in the second matrix,and when the letter is through the first matrix the next letter has to start running in the first matrix. so there are several things happening at the same time. i cant figure out a good way to simplify it in functions. i hope it is understandable where my problem lies.
thanks

Hi, seems like you missed this section in the LedControl-docs
http://www.arduino.cc/playground/Main/LedControl#RowMatrixControl
:

A note on performance...

There is an important difference between the way the setRow()- and the setColumn()- methods update the Leds:

  • setRow() only needs to send a single int-value to the MAX72XX in order to update all 8 Leds in a row.
  • setColumn() uses the setLed()-method internally to update the Leds. The library has to send 8 ints to the driver, so there is a performance penalty when using setColumn(). You won't notice that visually when using only 1 or 2 cascaded Led-boards, but if you have a long queue of devices (6..8) which all have to be updated at the same time, that could lead to some delay that is actually visible.

Changing your code from setColumn() to setRow() should give a great boost in performance.

Eberhard

In your original code:

 lc.setColumn(1,i-31,p[7]);
 lc.setColumn(1,i-32,p[6]);
 lc.setColumn(1,i-33,p[5]);
 lc.setColumn(1,i-34,p[4]);
 lc.setColumn(1,i-35,p[3]);
 lc.setColumn(1,i-36,p[2]);
 lc.setColumn(1,i-37,p[1]);
 lc.setColumn(1,i-38,p[0]);

the 2nd argument is decreasing, and the index in the 3rd argument is decreasing.

In this code:

for(byte i=0, j=0; i<8, j<=7;i++, j++)
{
 lc.setColumn(0,i,n[j]);
}

the arguments are increasing. Is that intentional? The column value always ranges from 0 to 7. It that intentional? Shouldn't there be some constant added to i?

Post all of your code, please.