SOLVED - How to define multiple blocks of data (array)

Hi all,

I know this is simple, but I'm just not seeing it.

Using the LiquidCrystal library, custom characters can be generated and loaded into the display like this:

    uint8_t custom0[] = { // a cute little star
        0b00000, // 
        0b10101, // #   #   #
        0b01110, //   # # #
        0b11111, // # # # # #
        0b01110, //   # # #
        0b10101, // #   #   #
        0b00000, //
        0b00000, //
    };
    LCD.createChar (0, custom0); // put the bitmap in LCD slot 0

Then, by doing [b]LCD.write (0);[/b] the custom character is printed.

Now, what I want to be able to do is define multiple characters with one variable name. Instead of "custom0", "custom1", "custom2", etc... what I want is something like this:

uint8_t *custom[] = {
    { first block of 8 bytes },
    { second block of 8 bytes },
    // etc....
    { eighth (and last) block of 8 bytes },
};

so that I can do this:

for (x = 0; x < 8; x++) {
    LCD.createChar (x, custom[x]); // define them all at once
}

and this:

for (x = 0; x < 8; x++) {
    LCD.write (custom[x]); // print all of them
}

For the life of me, I can't seem to figure out the proper syntax for the array definition.

Any help will be greatly appreciated. Thanks!

In that case you need a 2-dimensional array:

uint8_t *custom[][8] = {

Then custom[N] will be the address of the Nth custom character.

Pete

I think you want this.

uint8_t custom[][8] = { // a cute little star
  {
    0b00000, //
    0b10101, // #   #   #
    0b01110, //   # # #
    0b11111, // # # # # #
    0b01110, //   # # #
    0b10101, // #   #   #
    0b00000, //
    0b00000  }
  , //

  {
    0b00000, //
    0b10101, // #   #   #
    0b01110, //   # # #
    0b11111, // # # # # #
    0b01110, //   # # #
    0b10101, // #   #   #
    0b00000, //
    0b00000  }
  , //

  {
    0b00000, //
    0b10101, // #   #   #
    0b01110, //   # # #
    0b11111, // # # # # #
    0b01110, //   # # #
    0b10101, // #   #   #
    0b00000, //
    0b00000  } //
};

void setup()
{
  Serial.begin(9600);

  // array
  for(int i=0; i < 3; i++)
  {
    // each row
    for(int j=0; j < 8; j++)
    {
      Serial.print(i); 
      Serial.print(", ");
      Serial.print(j);
      Serial.print(":  ");
      Serial.println(custom[i][j], BIN);
    } 
  }

}

void loop()
{

}

el_supremo:
In that case you need a 2-dimensional array:

uint8_t *custom[][8] = {

Then custom[N] will be the address of the Nth custom character.

Pete

Almost. The syntax that Blue Eyes posted (custom[][8], not *custom[][8]) is correct.

Thank you both for the input. Problem solved, and karma++ for you both. Thanks!!

Thanks for the correction and karma :wink:

Pete

el_supremo:
Thanks for the correction and karma :wink:

Pete

You are welcomed, and thanks again for the help!