append 2 dimensional array in another array

Hi all

I developed a 5x5 LED matrix .

Now I want to develop a ticker.

For this I coded some letters in a two dimensional arrays

e.g. Letters X and M:

byte X_Array[5][5] = {
  {X, _, _, _, X},
  {_, X, _, X, _},
  {_, _, X, _, _},
  {_, X, _, X, _},
  {X, _, _, _, X},
};
byte M_Array[5][5] = {
  {X, _, _, _, X},
  {X, X, _, X, X},
  {X, _, X, _, X},
  {X, _, _, _, X},
  {X, _, _, _, X},
};

Now I need another array to store words or whole sentences.
In this new array single letters should be appended
How can I achieve this? How has the new array to look like?

Thanks
Regards
Mario

Well you could create a 3D array

Word[100][5][5] which would hold 100 letters but you are using your memory probably too agressivley

Your characters, as they seem to have less than 8 pixels in height or width could fit in a byte

So byte X_array[5] would be

B10001,
B01010,
B00100,
B01010,
B10001

Which uses only 5 bytes instead of 25. Multiply this by 50 to have all capital letters, numbers and a few symbols and you'll save tons of memory. And you can add an extra 0 column (in front but that's already there) and after the char drawing to create spacing in the display between letters at no extra memory cost because you have the byte anyway.

Your alphabet could then be a 2 D array

byte alphabet[50][5] = {
/* 0 */ {B01110, B10001,B10001,B10001,B01110},
/* 1 */ {....},
...
/* Z */ {....},
...
};

Of course this is constant so should be stored in PROGMEM. I would suggest you keep the same order as the ASCII table, this way you represent a string in memory just as a standard char array/string such as "HELLO WORLD" which will save tons of space in memory and when you decode to display, you just take each char in the string, subtract the ASCII code representation of '0' from it (if you coded from '0' onward) and you have the index in your array where to read the 5 bytes to build the display.

Also depending on how your LED matrix works (or how you rotate it on your board), I would actually represent the pixels as a column rather than row: This might seem counter intuitive but makes it easier to scroll horizontally one column at a time for smooth display with less bit manipulation as you have one full column as a byte.

If you have 2 LED matrix elements you can keep 2x5 bytes to hold the current display bits horizontally and just do some bit manipulation to shift them left before injecting a new column as you scroll.

To do this, you would declare an an array of pointers to your 2-d arrays. YOu would make the final pointer in that array NULL.

It looks like this:

byte X_Array[5][5] = {
  {'X', '_', '_', '_', 'X'},
  {'_', 'X', '_', 'X', '_'},
  {'_', '_', 'X', '_', '_'},
  {'_', 'X', '_', 'X', '_'},
  {'X', '_', '_', '_', 'X'},
};
byte M_Array[5][5] = {
  {'X', '_', '_', '_', 'X'},
  {'X', 'X', '_', 'X', 'X'},
  {'X', '_', 'X', '_', 'X'},
  {'X', '_', '_', '_', 'X'},
  {'X', '_', '_', '_', 'X'},
};


byte (*xmmx[])[5] = {
  X_Array,
  M_Array,
  M_Array,
  X_Array,
  NULL
};

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  while (!Serial);
  Serial.print("starting sketch in");
  for (int i = 3 ; i > 0; i--) {
    Serial.print(' ');
    Serial.print(i);
    delay(1000);

  }
  Serial.println();

  for (int i = 0; xmmx[i]; i++) {
    Serial.print("Character ");
    Serial.println(i);

    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 5; k++) {
        Serial.print((char)xmmx[i][j][k]);
      }
      Serial.println();
    }
    Serial.println();

  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

PaulMurrayCbr:
To do this, you would declare an an array of pointers to your 2-d arrays. YOu would make the final pointer in that array NULL.

Yes of course that's better than duplicating data in memory!

My view though is that it's even better to maintain the char array because it's one byte per letter and makes things easy then

Hi all,

thx for the replies!

I will try the byteArray. I only can Code JAVA, VB, ABAP but no C!

The ByteArrays are new for me and sound interesting!

Regards
Mario

sorry, I need some help.
How do I iterate over a byte array?
Could you give an example please?

Thanks
Mario

@Paul,

I tested your code.
The only thing I see is:

starting sketch in 3 2 1
Character 0
...
Character 1
...
Character 2
...
Character 3

:frowning:

mariomueller:
@Paul,

I tested your code.
The only thing I see is:

starting sketch in 3 2 1

Character 0
...
Character 1
...
Character 2
...
Character 3





:-(

Do you have the correct baud rate on your serial monitor? I get this:

starting sketch in 3 2 1
Character 0
X___X
_X_X_
__X__
_X_X_
X___X

Character 1
X___X
XX_XX
X_X_X
X___X
X___X

Character 2
X___X
XX_XX
X_X_X
X___X
X___X

Character 3
X___X
_X_X_
__X__
_X_X_
X___X

Can anyone else confirm that my sketch works/does not work?