Help With a 2D Char Array

Hello,

I am trying to make a code that creates a string array that I can then convert to a char array using toCharArray to pass through an 8x8 LED matrix. I currently have the following code to try and take the input message and parse through it (using for and if loops) to add the correct series of bits to create a scrolling message on the LED matrix. While I was coding before, I had it working (testing only on Serial moniter) however, I had forgotten to close of the if statement and now that the if statement is closed, I am getting random garbage on the Serial moniter rather than my string arrays. Can you help?

char input_message[] = "AB"; //INSERT input_message HERE
String message[7] = {"","","","","","",""};

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  Serial.println(sizeof(input_message));
  // put your main code here, to run repeatedly:
  for (int i = 0; i < sizeof(input_message)-1; i ++) {
    if (input_message[i] == 'A') {
      for (int j = 0; j < 7; j ++) {
        for (int k = 0; k < 6; k++) {
          message[j] = message[j] + String(A[j][k]);
        }
        
      }
    }
    if (input_message[i] == 'B') {
      for (int j = 0; j < 7; j ++) {
        for (int k = 0; k < 6; k++) {
          message[j] = message[j] + String(B[j][k]);
        }
        
      }
    }
    if (input_message[i] == 'C') {
      for (int j = 0; j < 7; j ++) {
        for (int k = 0; k < 6; k++) {
          message[j] = message[j] + String(C[j][k]);
        }
        
      }
    }
    if (input_message[i] == 'D') {
      for (int j = 0; j < 7; j ++) {
        for (int k = 0; k < 6; k++) {
          message[j] = message[j] + String(D[j][k]);
        }
        
      }
    }
char A[7][6] = {"011100", "100010", "100010", "111110", "100010", "100010", "100010"};
char B[7][6] = {"111100", "100010", "100010", "111100", "100010", "100010", "111100"};
char C[7][6] = {"011100", "100010", "100000", "100000", "100000", "100010", "011100"};
char D[7][6] = {"111100", "100010", "100010", "100010", "100010", "100010", "111100"};

sketch_mar30a.ino (11.3 KB)

Capture.JPG

capture 2.JPG

More members will see your code if you post it as described in the how to use this forum sticky.

groundFungus:
More members will see your code if you post it as described in the how to use this forum sticky.

So sorry. I am very new to posting in forums like this and didn't see that sticky before I posted

i think this would be much easier is you manage your data as ascii strings, not as a "String" or as individual characters.

instead of defining an 2 dimensional array of characters, you can define an array of strings.

and since all your string arrays have the same number of strings, you can simply use a **char pointer to reference the string array you're interested in.

consider the following code

# include <stdio.h>
# include <string.h>

const char *A[] = {"011100", "100010", "100010", "111110", "100010", "100010", "100010"};
const char *B[] = {"111100", "100010", "100010", "111100", "100010", "100010", "111100"};
const char *C[] = {"011100", "100010", "100000", "100000", "100000", "100010", "011100"};

int
main ()
{
    char input_message [] = "ABC";
    char **msg;

    for (int i = 0; strlen (input_message) > i; i++)  {
        switch (input_message [i])  {
        case 'A':
            msg = (char **)A;
            break;

        case 'B':
            msg = (char **)B;
            break;

        default:
            msg = (char **)C;
            break;
        }

        for (int i = 0; i < 7; i++)  {
            printf ("  %s\n", msg [i]);
        }
        printf ("\n");
    }
}