Assigning value to an array of arrays (multidimensional array)

I have declared several arrays such as:

byte Space[] = { B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000 };

Now I need to declare and assign values to it. I tried several syntaxes but I keep getting the errors:

byte myText1[16][8]; * *myText1={ Dalet,Vav,Dalet,Space,Shin,Kuf,Vav,Lamed,Yud,Nun,Kuf,Space,Space,Space,Space};

/tmp/308757365/writting_hebrew/writting_hebrew.ino:321:9: error: assigning to an array from an initializer list

Can you suggest the right syntax to define myText1?

you just need to read up a bit more on using arrays. In the first example, B00000 is treated as a variable. If you intended those to be binary values, they would be 0B00000000.

In the second, string literals are enclosed in double quotes and you need to include subscripts for you assignment -> myText1[][].

DKWatson:
you just need to read up a bit more on using arrays. In the first example, B00000 is treated as a variable. If you intended those to be binary values, they would be 0B00000000.

No.

All that Bxxxxx stuff is declared in some Arduino header file, so it works.

void setup() {
  Serial.begin(250000);
  Serial.println(B00000, BIN);
  Serial.println(B01010, BIN);
}
void loop() {}
0
1010

Whandall: All that Bxxxxx stuff is declared in some Arduino header file, so it works.

Sorry, I do my quick code tests in Notepad++ without all the Arduino attachments.

DKWatson: Sorry, I do my quick code tests in Notepad++ without all the Arduino attachments.

That is not the environment the TO is running his sketch on.

DKWatson: you just need to read up a bit more on using arrays. In the first example, B00000 is treated as a variable. If you intended those to be binary values, they would be 0B00000000.

In the second, string literals are enclosed in double quotes and you need to include subscripts for you assignment -> myText1[][].

Indeed B00000000 is OK. That part works.

Let me give some background: Once I've defined every letter of an alphabet, each being like :

byte Shin[] = { B00000, B10101, B10101, B01001, B00101, B00010, B00000, B00000 };

I want to make an array of the new alphabet letters. The reason is so that I can then loop through this array, letter by letter, calling for a procedure to print them in LCD.

So, the question is: If the array will be called myText1, and should contain 16 letters of this new alphabet, How to define it and how to assign it? Remember that the objective is to pick up elements one by one, being one element an array of 8 bytes like the one above.

Thanks.

You could store a list of pointers to the characters:

 byte *myText1[16] = { Dalet, Vav, Dalet, Space, Shin, Kuf, Vav, Lamed, Yud, Nun, Kuf, Space, Space, Space, Space};

If you really want to initialize the array at run time you have to do it with a loop but you could do it easily from an initialized list:

byte myText1[16][8];
byte *Message1[16] = {Dalet, Vav, Dalet, Space, Shin, Kuf, Vav, Lamed, Yud, Nun, Kuf, Space, Space, Space, Space};


void setup()
{
  for (int i = 0; i<16; i++)
  {
    for (int j=0; j< 8; j++)
    {
      myText[i][j] = Message1[i][j];
    }
  }
}

Note: You only have 15 characters in your 16 character array.

Expanding on @johnwasser’s post:

The compiler error you included in your original post was quite explicit about the problem. You were trying to do an assignment using syntax that is only allowed in an initialization.

You were not explicit enough in the description of your application to determine which one is required here. If the contents of your ‘myText1’ array is fixed and known at compile-time, then a constant initialization is the best way to go. If you need to dynamically (i.e. programmatically) change the array contents, then you must first define it and then assign its elements one by one. Both techniques are shown in the below.

const uint8_t bytesPerLetter = 8;

const uint8_t Space[bytesPerLetter] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

const uint8_t Shin[bytesPerLetter] = {
  B00000,
  B10101,
  B10101,
  B01001,
  B00101,
  B00010,
  B00000,
  B00000
};

const uint8_t * const myText1[] = {Shin, Space, Shin};
const uint8_t staticArraySize = sizeof(myText1) / sizeof(myText1[0]);

const uint8_t dynamicArraySize = 4;
const uint8_t *dynamicArray[dynamicArraySize];

void setup() {
  Serial.begin(115200);
  delay(2000);

  // Print the constant array
  Serial.println("Constant Array:");
  for (uint8_t i = 0; i < staticArraySize; i++) {
    Serial.print(i);
    Serial.print(": ");
    for (uint8_t j = 0; j < bytesPerLetter; j++) {
      Serial.print(*(myText1[i] + j), BIN);
      Serial.print(" ");
    }
    Serial.println();
  }
  Serial.println();

  // Assign to the dynamic array:
  dynamicArray[0] = Shin;
  dynamicArray[1] = Space;
  dynamicArray[2] = Space;
  dynamicArray[3] = Shin;

  // Print the Dynamic array
  Serial.println("Dynamic Array:");
  for (uint8_t i = 0; i < dynamicArraySize; i++) {
    Serial.print(i);
    Serial.print(": ");
    for (uint8_t j = 0; j < bytesPerLetter; j++) {
      Serial.print(*(dynamicArray[i] + j), BIN);
      Serial.print(" ");
    }
    Serial.println();
  }


}

void loop() {}