Array problem

Hi everyone.I want to interface 3x8x8 led matrix using 3 MAX72xx . I modified the library Led Control to work with x,y values and it works great. What i want to do is to get the characters from the font.h and copy the array of bytes in my array, and later to “print” this array. My copy function (void makeword) is not working so good…it is working perfectly for 1-5 characters.If i want to display 6 or more characters, my led display seems to be crazy :’( .If i want to display an array prebiosly declared and manually loaded like temp2 everything works perfectly, nomatter the number of characters. If i want to display the generated array it works for only 5 characters; if i want 6 or more it works desastrous.I try to search a function like memcpy which have to add to the end of my generated array, but i didn’t find…Any ideea ?
My code is this:

int k=0;
char text_afisare[] = "TESTTEST";
int nr_litere = strlen(text_afisare);
int nr_bytes = nr_litere*8;
byte temp[64];

byte temp2[328]={
              B00000000,B11000000,B11000000,B11111111,B11111111,B11000000,B11000000,B00000000,B00000000,B11111111,B11111111,B11011011,B11011011,B11011011,B11000011,B00000000,B00000000,B01110010,B11111011,B11011011,B11011011,B11011111,B01001110,B00000000,B00000000,B11000000,B11000000,B11111111,B11111111,B11000000,B11000000,B00000000,
              B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
              B00000000,B01111110,B11111111,B11000011,B11000011,B11111111,B01111110,B00000000,B00000000,B11111100,B11111110,B00000011,B00000011,B11111110,B11111100,B00000000,B00000000,B11111111,B11111111,B11011011,B11011011,B11011011,B11000011,B00000000,B00000000,B11111111,B11111111,B11001100,B11001100,B11111111,B01110111,B00000000,B00000000,B11111111,B11111111,B00111000,B00011100,B11111111,B11111111,B00000000,B00000000,B11111111,B11111111,B11011011,B11011011,B11011011,B11000011,B00000000,B00000000,B11000000,B11000000,B11111111,B11111111,B11000000,B11000000,B00000000,
              B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
              B00000000,B11000000,B11000000,B11111111,B11111111,B11000000,B11000000,B00000000,B00000000,B11111111,B11111111,B11011011,B11011011,B11011011,B11000011,B00000000,B00000000,B01110010,B11111011,B11011011,B11011011,B11011111,B01001110,B00000000,B00000000,B11000000,B11000000,B11111111,B11111111,B11000000,B11000000,B00000000,
              0x08, 0x04, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 
              0x10, 0x20, 0x40, 0x80, 0x80, 0x02, 0x02, 0x02, 
              0x99, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x99, 
              0xFF, 0x81, 0xBD, 0xA5, 0xA5, 0xBD, 0x81, 0xFF,
              0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 
              0x33, 0x33, 0xCC, 0xCC, 0x33, 0x33, 0xCC, 0xCC, 
              0x42, 0xC3, 0x24, 0x18, 0x18, 0x24, 0xC3, 0x42, 
              0xFD, 0x85, 0xB5, 0xA5, 0xA5, 0xBD, 0x81, 0xFF, 
              0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
              0xFF, 0x7E, 0x7E, 0x7E, 0x7E, 0x42, 0x24, 0x18,
              0x18, 0x18, 0x3C, 0x66, 0x66, 0x3C, 0x18, 0x18,
              0x78, 0x78, 0x18, 0xFF, 0xFF, 0x0C, 0x3C, 0x3C, 
              0xF2, 0x82, 0x12, 0x3A, 0x10, 0xC0, 0xC4, 0x0E,
              0x7F, 0x84, 0xA7, 0x84, 0xA7, 0x84, 0x7F, 0x00, 
              0x3C, 0x42, 0x81, 0xA1, 0x89, 0x95, 0xA5, 0x42, 
              0x07, 0x2F, 0x1C, 0x3E, 0x3C, 0x30, 0x30, 0x30, 
              0x5A, 0x99, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 
              0x82, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x41,
              0x00, 0x01, 0x06, 0x7E, 0xDF, 0x7E, 0x06, 0x01, 
              0x04, 0x0F, 0x1F, 0x3C, 0x3C, 0x1F, 0x0F, 0x04,
              0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 
              0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
              0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x49, 0x92,
              0x92, 0x49, 0x24, 0x92, 0x49, 0x24, 0x92, 0x49            
          };

void setup() {
  lc.shutdown(0,false);
  lc.shutdown(1,false);
  lc.shutdown(2,false);
  lc.setIntensity(0,15);
  lc.setIntensity(1,15);
  lc.setIntensity(2,15);
  lc.clearDisplay(0);
  lc.clearDisplay(1);
  lc.clearDisplay(2);
  makeword(text_afisare);
  
}

void initializare(){
    lc.setIntensity(0,15);
    lc.setIntensity(1,15);
    lc.setIntensity(2,15);
    lc.clearDisplay(0);
    lc.clearDisplay(1);
    lc.clearDisplay(2);
}

void matrice(unsigned long delaytime, byte character[]) {
  lc.clearDisplay(0);                                    
  lc.clearDisplay(1);                                    
  lc.clearDisplay(2);                                      
  for(int i=23;i>=-nr_bytes;i--) {                                      
    for(int j=0;j<(24-i);j++) {
      if(j < nr_bytes) {
        scrie_coloana(i+j, character[j]);
      } else {
        scrie_coloana(i+j, false);
      }
    }
    delay(delaytime);
  } 
   
}


void makeword(char text[])
{
  for(int i=0;i<nr_litere;i++)
  {
    int val=0;
    char ch=text[i];
    if (ch < 32 || ch > 126){
    ch = 32;
    }
    ch -= 32;
    //for(int j=0;j<8;j++)
    //{
      temp[k]=font[ch][val];
      temp[k+1]=font[ch][val+1];
      temp[k+2]=font[ch][val+2];
      temp[k+3]=font[ch][val+3];
      temp[k+4]=font[ch][val+4];
      temp[k+5]=font[ch][val+5];
      temp[k+6]=font[ch][val+6];
      temp[k+7]=font[ch][val+7];
      k+=8;
    //}
    
    //memcpy(temp,font[ch],8);
    //temp[k]=font[ch];
    //k+=8;
  }
}
  
void scrie_coloana(int coloana, byte informatie)  
  {
  if(coloana<=7) lc.setRow(0,coloana,informatie);
  if(coloana<=15) lc.setRow(1,coloana-8,informatie); 
  if(coloana<=23) lc.setRow(2,coloana-16,informatie);
  }
  
void loop() { 
  delay(1000);
   initializare();
   matrice(100,temp);
}

PS : Sorry for my bad english :frowning:

Which Arduino are you using?

Dueamilanove with ATmega 168. I think it's a memory problem ... i think i should allocate the mamory dinamically for my temp[]

Well, I always like dynamic mammaries.

Hi again...now i have a bigger problem ... i tried to allocate the memory for temp[] dinamically ... so my temp is like:

byte* temp=new byte[64];

But when i try to compile this is happening:

o: In function `__static_initialization_and_destruction_0':
C:\Documents and Settings\over\Desktop\incercarea_numarul_2_la_hmm/applet\incercarea_numarul_2_la_hmm.cpp:23: undefined reference to `operator new[](unsigned int)'

What is this error and how can i fix it ? Is my code faulty ?

Thanks

By default, the new and delete operators are not defined. There are a number of threads in the forum that explain how and where to define them. Happy hunting.

Code dealing with static arrays is much easier to debug, by the way, than code dealing with dynamic ones.

Now i'm stuck.I allocated the temp[] variable dinamically and it seems not to work.Same garbage, same problems.I don't know what is wrong... When i try to disply for example "TESTTEST" i obtain 3 'dots" - leds of garbage....If i try to display "TEST" or maximum 6 letters on my display appears only 4 letters...first letters and lot of garbage ...

my array is next

byte* temp;

and i added in makeword(char*)

temp=(byte*)malloc(nr_bytes*sizeof(byte));

I also tried to make char*temp; of course with all the modification necesaire... I don't really understand where is the fault... For more than 8 letters my arduino seems to be dead...cannot even blink a led, operation made in loop...

I went back and looked at your original code. You have lines like this:

      temp[k]=font[ch][val];

The posted code does not have a definition/declaration for font. Tell us about font, please.

I suspect that you are running out of memory. What is the temp2 array for? It does not appear to be used.

First of all thanks again Paul.
My font is

const byte font[][8] = {
            {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},   //   0x20 32
            {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},   // ! 0x21 33
            {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},   // " 0x22 34
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
            {B00000000,B11111111,B11111111,B11011011,B11011011,B11011011,B11000011,B00000000},   // E 0x45 69
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
            {B00000000,B11111111,B11111111,B00111000,B00011100,B11111111,B11111111,B00000000},   // N 0x4e 78
            {B00000000,B01111110,B11111111,B11000011,B11000011,B11111111,B01111110,B00000000},   // O 0x4f 79
                {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},   // S
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
            {B00000000,B11111111,B11111111,B11001100,B11001100,B11111111,B01110111,B00000000},   // R 0x52 82
                {B00000000,B01110010,B11111011,B11011011,B11011011,B11011111,B01001110,B00000000},   // S
            {B00000000,B11000000,B11000000,B11111111,B11111111,B11000000,B11000000,B00000000},   // T 0x54 84
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
            {B00000000,B11111100,B11111110,B00000011,B00000011,B11111110,B11111100,B00000000},   // V 0x56 86
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000},
{B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000}
};

I have not yet loaded all values for my letters, only few of them.
I also tried to use in makeword(char* ) procedure a for instruction:

void makeword(char text[])
{
  temp=(char *)malloc(nr_bytes*sizeof(char));
  for(x=0;x<nr_bytes;x++) temp[x]=B00000000;
  for(i=0;i<nr_litere;i++)
  {
    ch=text[i];
    if (ch < 32 || ch > 126){
    ch = 32;
    }
    ch -= 32;

    for(j=0;j<8;j++)
    {
      temp[k++]=font[ch][j];
    //k++
    }
  }
}

temp2 is for test.If i matrice(temp2) i could verify that may display function (matrice(byte*)) works fine.It’s not necesaire this varible.
I also suspect that it’s a memory problem, because if i declare the temp last varible and i do all my local variable Global i could Display 5 letters without garbage…so my conclusion : my microcontroller seems to be confused with some memory adress

Search the forum. There is a FreeMemory program/function that you can use. You are trying to store way to much stuff in the Arduino's memory. The 168 that you said you are using only has 16K of memory, with 2K being reserved for the bootloader. I do believe you are needing more than that.

I have already think at that.I removed the bootloder and ereased all my 168 and i uploded via icsp with pony prog the hex file.Same problem of course. I change the microcontroller ATmega 168 with Atmega328, load the bootloader via pony prog and tested my program.Same result.I erased the bootloader and load the hex file manually (on 328 chip) - same result ... i think it's a problem of memory allocation... Is not size the problem...because if i let all the sketch and try to (matrice temp2[]) everything works perfectly....so where could be the problem ?

Hi again. I come back with few additions.I changed a little the source code and i use #define for my letters, instead of that big 98 with 8 byte matrix for my font.It seems to work fine.I put my text in a matrix[number_of_characters][8] and with matrice(matrix[][]) i print the letters on my led disply.

Thanks again guys