2D array works. 3D doesn't.


hi, arduino forum.

i have been stuck on problem day , can't figure out why array doesn't work. if array works, replace awful long switch case function.

i no errors. program not output anything.

this program controlling rgb led array.

here piece of code. function "writeletter" not work, though difference 1 more array within array. function "lettera" works should.

the difference is:

from:
code: [select]
a[5][5]
to:
code: [select]
letterarray[256][5][5]

and

from:
code: [select]
a[4-y][x]
to:
code: [select]
letterarray[(int)letter-65][4-y][x]

i call function
code: [select]
writeletter('a', 2, 2, 0, 50, 50);.

code: [select]
void writeletter(char letter, int width, int height, int red, int green, int blue)
{
  //boolean [antall-char(tegn)][char-width][char-height]
  boolean letterarray[256][5][5] = {//a
                                   {{0, 0, 1, 0, 0},
                                    {0, 1, 0, 1, 0},
                                    {1, 1, 0, 0, 1},
                                    {1, 1, 1, 1, 1},
                                    {1, 1, 0, 0, 1}},
                                    //b
                                   {{1, 1, 1, 1, 0},
                                    {1, 1, 0, 0, 1},
                                    {1, 1, 1, 1, 0},
                                    {1, 1, 0, 0, 1},
                                    {1, 1, 1, 1, 0}}};
 
 
  serial.println(((int)letter)-65);
  uint32_t color = strip.color(red, green, blue);
                     
  for(int x = 0; x < 5; x++)
  {
    for(int y = 0; y < 5; y++)
    {
      if(width > width-5 && letterarray[(int)letter-65][4-y][x] == true) strip.setpixelcolor(width + x + y*width + (height-1)*width, color);
      else if(letterarray[(int)letter-65][4-y][x] == true) strip.setpixelcolor(width + x + y*width + height*width, color);
    }
  }
}





//  y
//  ^
//  |     #
//  |   #   #
//  | # #     #
//  | # # # # #
//  | # #     #
//  ------------> x
void lettera(int width, int height, int red, int green, int blue)
{
  uint32_t color = strip.color(red, green, blue);
  boolean a[5][5] = {{0, 0, 1, 0, 0},
                     {0, 1, 0, 1, 0},
                     {1, 1, 0, 0, 1},
                     {1, 1, 1, 1, 1},
                     {1, 1, 0, 0, 1}};                   
  for(int x = 0; x < 5; x++)
  {
    for(int y = 0; y < 5; y++)
    {
      if(width > width-5 && a[4-y][x] == true) strip.setpixelcolor(width + x + y*width + (height-1)*width, color);
      else if(a[4-y][x] == true) strip.setpixelcolor(width + x + y*width + height*width, color);
    }
  }
}



thank thought.

strange. if use "boolean letterarray[ x ][5][5]"
where x=2, 3, 4...19, 20
it works. more 20, makes crazy light shows. more 50, , doesn't work @ all.

input?


Arduino Forum > Using Arduino > Programming Questions > 2D array works. 3D doesn't.


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code