LED matrix font library???

Greetings, all -

I've gotten a simple LCD matrix working and scrolling characters but I can't seem to find the room for the whole alphabet on the mega (or at east that's what I assume my problem is). I'm sure there's probably a better way to do this but I've basically just declared one matrix as the "frame" and another matrix to hold the character coming into frame and a function just passes columns from the "buffer" matrix into the frame matrix one column at a time until the buffer matrix is empty.

I had gone ahead at the beginning and made a small matrix for each letter of the alphabet to write into the buffer matrix when needed and was successful in scrolling these characters. I then went back and added the rest of the alphabet but when I get 21 letters into the case statement (at the bottom of the code), the unit just stops responding altogether. When I comment out one letter's case it all comes back up. Is this a memory issue? The reason I'm asking in this section is that I'm curious to know if putting the font in a library or some other external file would help? If so, I have no idea how to do this. I found the tutorial on library creation on the arduino site but it seems to be oriented toward class construction and I don't know that data types are necessarily beneficial to this problem (but they may be!). I don't know... a bit stuck at this point.

The code is included but please don't laugh too hard. My plan was to somewhat "brute force" the thing and then go back and condense where I could. Yes - I'll admit - the thought "Oh - yeah - libraries... Kinda like referencing external javascript files... Shouldn't be that bad..." crossed my mind. And it may not be that bad, lol. Anyway, just trying to find the best approach for this application.

Thanks!

int rowPins[5] = {9, 10, 11, 12, 13};
int colPins[8] = {2, 3, 4, 5, 6, 7, 8};
int dly = 4;
int baseCol, holdCount, inByte, chrWidth, getNextChr, chrScrolledCols = 0;
//serial string read
int serialInput[200];
int serCount, charPos, serRead = 0;


//scroll matrix - holds current character being placed onto the frame
int scrMat[5][5] = {
  {0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0}};

//matrix to scan for actual frame output
int frameMat[5][13] = {
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}};
  
//letter A
int chA[5][6] = {
  {3, 0, 1, 0},
  {0, 1, 0, 1},
  {0, 1, 1, 1},
  {0, 1, 0, 1},
  {0, 1, 0, 1}};

// and so on for letters "B"-"Y"
  
//letter Z
int chZ[5][6] = {
  {3, 1, 1, 1},
  {0, 0, 0, 1},
  {0, 0, 1, 0},
  {0, 1, 0, 0},
  {0, 1, 1, 1}};
  
//space
int chSpc
[5][6] = {
  {2, 0, 0, 0},
  {0, 0, 0, 0},
  {0, 0, 0, 0},
  {0, 0, 0, 0},
  {0, 0, 0, 0}};

void setup(){
  
  Serial.begin(9600);
  
  for (int initCounter = 0; initCounter < 5; initCounter++){
    pinMode(rowPins[initCounter], OUTPUT);
  }
  for (int initCounter = 0; initCounter < 7; initCounter++){
    pinMode(colPins[initCounter], OUTPUT);
  }
}

void loop(){
  
  scanFrame();
  scrFrameOneColLeft();
  if (Serial.available()){
    for (int i = 0; i < 200; i++){
      serialInput[i] = 0;
    }
    charPos = 0;
    readSerial();
    
    chrScrolledCols = 0;
  }
}

void scrFrameOneColLeft(){
  int currentCol = 0;
  for (int frameRow = 0; frameRow < 5; frameRow++){
    while (currentCol < 12){
      frameMat[frameRow][currentCol] = frameMat[frameRow][currentCol + 1];
      currentCol++;
    }
    currentCol = 0;
  }
  chrScrolledCols++;
  if (chrScrolledCols == chrWidth + 1){
    //Serial.println("~");
    chrScrolledCols = 0;
    
    if (serialInput[charPos
    
    ] != 0){
      addChar();
      //Serial.println("charPos = ");
      
      //Serial.println(charPos);
      
      charPos++;
    }
  }
}

void scanFrame(){
  int scanCount = 0;
  //only scan frameMat and manipulate values for scrolling effect
  while (scanCount < 10){
  //set row states first to eliminate unnecessary "flicker"
    for (int currentColRead = 0; currentColRead < 7; currentColRead++){
      //clear columns
      for (int initCounter = 0; initCounter < 7; initCounter++){
        digitalWrite(colPins[initCounter], LOW);
      }
      //read row states for current column
      for (int currentRowRead = 0; currentRowRead < 5; currentRowRead++){
        if (frameMat[currentRowRead][6 - currentColRead] == 0){
          digitalWrite(13 - currentRowRead, HIGH);
        }
        else{
          digitalWrite(13 - currentRowRead, LOW);
        }
      }
      //set currentcolumn high
      digitalWrite(8 - currentColRead, HIGH);
      delay(1);
    }
    
    scanCount++;
  }
}

  void readSerial(){
    //read string from serial
    while (Serial.available() != 0){
      serialInput[serCount] = Serial.read();
    
      
      Serial.println(serialInput[serCount], BYTE);
    
      serCount++;
    }
    serCount = 0;
  }
  
  void addChar(){
    
  serRead = serialInput[charPos];
  switch (serRead){
  case 32:
    chrWidth = chSpc[0][0];
    for (int chrCol = 1; chrCol <= chSpc[0][0]; chrCol++){
      for (int chrRow = 0; chrRow < 5; chrRow++){
        frameMat[chrRow][6 + chrCol] = chSpc[chrRow][chrCol];
      }
    }
  break;
  case 65:
    chrWidth = chA[0][0];
    for (int chrCol = 1; chrCol <= chA[0][0]; chrCol++){
      for (int chrRow = 0; chrRow < 5; chrRow++){
        frameMat[chrRow][6 + chrCol] = chA[chrRow][chrCol];
      }
      
    }
  break;
// and so on for letters "B"-"Y"
  case 90:
    chrWidth = chZ[0][0];
    for (int chrCol = 1; chrCol <= chQ[0][0]; chrCol++){
     for (int chrRow = 0; chrRow < 5; chrRow++){
        frameMat[chrRow][6 + chrCol] = chZ[chrRow][chrCol];
      }
    }
  break;
  }
}

first change all the definitions of int ch.... to byte ch... that will save already a lot of space about half of your tables.

Then go read up on PROGMEM (storing data in program memory not in RAM

http://www.arduino.cc/playground/Main/PROGMEM

Thanks for the suggestion on the int/char usage. That did it!

Very interested in the PROGMEM route as well. Thanks for the link!