Printing Tri-dimensional Matrixes with triple for's

Hello Everyone,

Well, I'm currently working on a LET matrix display, and I'm using a tri dimensional boolean-type matrix to store values for LED's statuses when displaying each letter as follows:

#include <avr/pgmspace.h>

PROGMEM boolean CharacterVector[26][8][5] = {
{
{1,1,1,1,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,1,1,1,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1}
},{
{1,1,1,1,1},
{0,1,0,0,1},
{0,1,0,0,1},
{0,1,1,1,0},
{0,1,0,0,1},
{0,1,0,0,1},
{0,1,0,0,1},
{1,1,1,1,1}
},{
{1,1,1,1,1},
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,0,0,0},
{1,1,1,1,1}
},{
{1,1,1,1,0},
{0,1,0,0,1},
{0,1,0,0,1},
{0,1,0,0,1},
{0,1,0,0,1},
{0,1,0,0,1},
{0,1,0,1,1},
{1,1,1,1,0}
},{
{1,1,1,1,1},
{1,0,0,0,0},
{1,0,0,0,0},
{1,1,1,1,0},
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,0,0,0},
{1,1,1,1,1}
},{
{1,1,1,1,1},
{1,0,0,0,0},
{1,0,0,0,0},
{1,1,1,1,0},
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,0,0,0}
},{
{1,1,1,1,1},
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,0,0,0},
{1,0,1,1,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,1,1,1,1}
},{
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,1,1,1,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1}
},{
{1,1,1,1,1},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{1,0,1,0,0},
{0,0,1,0,0},
{1,1,1,1,1}
},{
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},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0}
},{
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,1,1,1,1}
},{
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{0,1,0,1,0},
{0,0,1,0,0}
},{
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,1,0,1},
{1,1,0,1,1},
{1,0,0,0,1}
},{
{1,0,0,0,1},
{1,0,0,0,1},
{0,1,0,1,0},
{0,0,1,0,0},
{0,1,0,1,0},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1}
},{
{1,0,0,0,1},
{0,1,0,1,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,1,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0}
},{
{1,1,1,1,1},
{0,0,0,0,1},
{0,0,0,0,1},
{0,0,0,1,0},
{0,0,1,0,0},
{0,1,0,0,0},
{1,0,0,0,0},
{1,1,1,1,1}
}
};

I used the pgmspace lib cause I was having issues with RAM on the UNO.
Still, one would think that I could get the first letter printed out to the serial port by using this:

for(int i=0 ; i<8 ; i++){
    for(int j=0 ; j<5; j++){
      Serial.print(CharacterVector[0][i][j]);
      Serial.print(" ");
    }
    Serial.print("\n");
  }

but what I get at the Serial Port is this:

0 0 2 0 0
0 1 0 0 2
2 2 2 2 2
2 0 0 135 0
0 2 0 0 1
3 0 2 103 0
0 0 0 0 0
0 2 2 2 2

when I should be getting this:

1 1 1 1 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 1 1 1 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1

So, I tried it out without using for's, the most straightforward way to print it:

Serial.print(CharacterVector[0][0][0]);
Serial.print(CharacterVector[0][0][1]);
Serial.print(CharacterVector[0][0][2]);
Serial.print(CharacterVector[0][0][3]);
Serial.print(CharacterVector[0][0][4]);
Serial.print("\n");
Serial.print(CharacterVector[0][1][0]);
Serial.print(CharacterVector[0][1][1]);
Serial.print(CharacterVector[0][1][2]);
Serial.print(CharacterVector[0][1][3]);
Serial.print(CharacterVector[0][1][4]);
Serial.print("\n");
Serial.print(CharacterVector[0][2][0]);
Serial.print(CharacterVector[0][2][1]);
Serial.print(CharacterVector[0][2][2]);
Serial.print(CharacterVector[0][2][3]);
Serial.print(CharacterVector[0][2][4]);
Serial.print("\n")
Serial.print(CharacterVector[0][3][0]);
Serial.print(CharacterVector[0][3][1]);
Serial.print(CharacterVector[0][3][2]);
Serial.print(CharacterVector[0][3][3]);
Serial.print(CharacterVector[0][3][4]);
Serial.print("\n")
Serial.print(CharacterVector[0][4][0]);
Serial.print(CharacterVector[0][4][1]);
Serial.print(CharacterVector[0][4][2]);
Serial.print(CharacterVector[0][4][3]);
Serial.print(CharacterVector[0][4][4]);
Serial.print("\n")
Serial.print(CharacterVector[0][5][0]);
Serial.print(CharacterVector[0][5][1]);
Serial.print(CharacterVector[0][5][2]);
Serial.print(CharacterVectors[0][5][3]);
Serial.print(CharacterVector[0][5][4]);
Serial.print("\n")
Serial.print(CharacterVector[0][6][0]);
Serial.print(CharacterVector[0][6][1]);
Serial.print(CharacterVector[0][6][2]);
Serial.print(CharacterVector[0][6][3]);
Serial.print(CharacterVector[0][6][4]);
Serial.print("\n")
Serial.print(CharacterVector[0][7][0]);
Serial.print(CharacterVector[0][7][1]);
Serial.print(CharacterVector[0][7][2]);
Serial.print(CharacterVector[0][7][3]);
Serial.print(CharacterVector[0][7][4]);

and get the expected output.
I've even tried substituting the term CharacterVector[0][j] for CharacterVector[0][0][0] or CharacterVector[0][1][1] to get all 1's and all 0's 8x5 matrixes respectively, and it works. It just doesnt seem to work when I try it with the indexes i and j in between the for's.
Any help would be much appreciated.

Out of curiosity, does it work if you do something like this:

for(int i=0 ; i<8 ; i++){
    for(int j=0 ; j<5; j++){
      if(CharacterVector[0][i][j])
         Serial.print("1 ");
      else
         Serial.print("0 ");
    }
    Serial.print("\n");
  }

Trying to isolate this to either Serial or indexing/memory related issue.

Hello and welcome!

I'm not sure but, try this:

Serial.print( pgm_read_byte(&CharacterVector[0][i][j]) );

I remember another topic with the same problem, I'll try to find it for you.
~~Edit: here it is: http://arduino.cc/forum/index.php/topic,120603.0.html~~

@guix

IT WORKED! what sort of black magic is that?

why not pack the latter 5 into one byte? (boolean is byte size too)

PROGMEM boolean CharacterVector[26][8] = {
{
0b11111, 0b10001, 0b1001, etc

uses only 208 bytes versus 1040 bytes.

for (int outer = 0; outer < 28; outer ++)
{
  for(int inner = 0 ; inner < 8 ; inner++)
  {
    for(int bit = 0 ; bit < 5; bit++) 
    {
      Serial.print( CharacterVector[outer][inner] & ( 0x01 << bit), DEC);     
      Serial.print(" ");
    }
    Serial.print("\n");
  } 
  Serial.print("\n");
}

give it a try

for (int outer = 0; outer < 28; outer ++)26 would be better

katupiry:
Well, I'm currently working on a LET matrix display, and I'm using a tri dimensional boolean-type matrix to store values for LED's statuses when displaying each letter as follows:

#include <avr/pgmspace.h>

PROGMEM boolean CharacterVector[26][8][5] ..

Hi!

There are several problems with your code.

  1. It is very inefficient and uses a lot of program memory. If boolean/bool is int then it is 16-bits per bit!
  2. Storing in program memory requires reading with special functions; pgm_read_byte()

Best advice I can give you if you want to learn more about this is to study how fonts are handled in one of the LCD graphics libraries (GLCD, TFTLib, etc).
http://code.google.com/p/glcd-arduino/source/browse/trunk/glcd/fonts/fixednums8x16.h

Simples you can do is to download the system font:
http://code.google.com/p/glcd-arduino/source/browse/trunk/glcd/fonts/SystemFont5x7.h

And reuse it and the access functions (basically mapping from the character to a start index in the font vector and the reading the bitmap with pgm_read_byte()).

Cheers!