Arrays inside of a array

I am working an a duplex-ed led display and I am defining the letters using x,y values like so.

int ascii(char letter){

if (letter==*"0"){
int L[]= {{1,1},{1,2},{2,2},{2,3},{2,4},{2,5},{1,6},{2,6},{3,6}};//[ERROR HERE]
}
else{L[]={{0,1}} }

return L
}

[ERROR]:display:4: error: braces around scalar initializer for type 'int' I don't understand C++ arrays or the error above^^^ any help?

I'm not going to ask about your logic with the IF statement, but you have a 2D array so the compiler wants it to be int L[][2]

I made the string in the if statement a pointer because I was getting the error ISO C++ forbids comparison between pointer and integer. it seams to do the trick is their a better way?.. (i’m used to python) I made the changes with the array and now I have two more questions, I am trying to find answers on google but the answers are really specific and I cant seam to adapt it too my code. First problem I tried pre-defining the array like so.

int L[24][2];

L= {{1,1},{1,2},{2,2},{2,3},{2,4},{2,5},{1,6},{2,6},{3,6}};//[line of ERROR]

and got.

error: expected primary-expression before ‘{’ token

The other Problem is how do i return the array L I have tried
return L;
but get

error: invalid conversion from ‘int (*)[2]’ to ‘int’
my guess is the return type of the function? thanks for your help so-far :smiley:

I love the effort you have put in: if(letter==*"0"),

You cannot assign to arrays.

L = { ... };

Only initialize:

int L[] = { ... };

As HazardsMind said, your data is for a multi-dimensional array, not a single dimension type like you have defined 'L'.

You need some more background knowledge, check out the C++ tutorials, and the array section, but not just the array section. http://www.cplusplus.com/doc/tutorial/ http://www.cplusplus.com/doc/tutorial/arrays/

Also your if statement can be more easily typed as:

if( letter== '0' )

I have read that entire page more than once. I dont see where it helps me with my problem. I need to asign an new value to the arrays ID not to a index. I can do that only when i first declare it tho. And at no point does to show how to return a array. Should i store the array in a class and pass the pointer?

int L[20][2]= {{1,1},{1,2},{2,2},{2,3},{2,4},{2,5},{1,6},{2,6},{3,6}};//[ERROR HERE]

void setup()
{
  Serial.begin(115200);
  int * tmp = ascii(3); // store returned pointer in tmp pointer
  Serial.print(tmp[0]); // show what is in element 0
  Serial.print(tmp[1]); // show what is in element 1
}

void loop() { }

int * ascii(int idx) // returns a pointer
{
  return L[idx]; // return a pointer to the data at idx
}

I need to asign an new value to the arrays ID not to a index.

What does this mean? You can't assign a new value to the name of the array. At run time, arrays (and other variables) do not have names.

Okay maybe i am looking at this wrong it looks like arrays are completely different in C than python. I think i might have to go with a structure like this demo uses http://www.mathias-wilhelm.de/arduino/assets/shields/dfrobot-lcd/DFrobotLCDBarChart.zip

Defining every character Globally then run through the input text to determine what to display... I think I will use all the ram tho running on uno (atmega328)... anyway to avoided this? I need to have this solved Sunday.

I think I will use all the ram tho running on uno (atmega328).

Use it for what? Not the arrays of data that define what to display. That is constant, and can live in PROGMEM.

I need to have this solved Sunday.

Nothing like waiting until the last minute to keep you focused. Good luck.

Not the arrays of data that define what to display. That is constant, and can live in PROGMEM.

but once i declare it it is put in ram tho... right? Okay instead of simplifying every thing : what i have is a function that takes X,Y coordinate and color (forgetting the color for now) I have a pixel map i made here http://images.actuateideas.com/General/projects/4X6.jpg and want to feed the values into the X,Y coordinate function one point at a time is their a better way to define and get the points?

but once i declare it it is put in ram tho... right?

The advantage behind using PGM functionality, is it resides in flash with out reducing RAM. The trade-off is the fact RAM can be accessed far quicker, as well as being random access. Flash memory is constant.

want to feed the values into the X,Y coordinate function one point at a time is their a better way to define and get the points?

Rather than having a raw data set, you could change to a single dimension array of objects. This may help with what you are conceptualizing:

struct Point{ 
  unsigned char X, Y;
 };

//Array of points:
Point points[] = {
  { 0, 1 },
  { 2, 3 },
  { 4, 5 },
  { 6, 7 },
};

Then all you have to pass is the point:

void Foo( Point &p ){
  Serial.print( "X: " );
  Serial.println(  p.x );
  Serial.print( "X: " );
  Serial.println(  p.y );
}

//Call with second element of array:
Foo( points[ 1 ] );

okay so after poking around and applying what i learned I came up with this
http://code.actuateideas.com/public/display/1.1/display.ino
it runs a bit slow and has a bad flicker… i still need to apply what I now know about arrays to the pin mapping part
to sum up calling an array from inside of an array you need to define the array when you pull it out!

bool cr_0[6][4]={
 {0,1,1,0},
 {1,0,0,1},
 {1,0,1,1},
 {1,1,0,1},
 {1,0,0,1},
 {0,1,1,0},
 };
for (int i = 0; i < 6; i++){
 //int * f=st_1[i];

  Y(i+Yy,high,high,0);//turns rail on--------------------------
  for (int e = 0; e < 4; e++){  
    bool * g=cr_0[i];//this was how i fixed calling an array inside of an array!!! you need to define the array when you pull it out!
   //Serial.println(g[e]);
  X(e+Xx,g[e]);//slect intersecting leds------------------------
  X(e+Xx,0);//reset intersecting leds------------------------
 }
 Y(i+Yy,0,0,0);//turns rail off------------------------------

if you want to fallow this project http://code.actuateideas.com/public/display/
Thank you all for your help!

Good to hear its running.

Your code style might lead you to disaster one day, I'm sure there are a few slightly more informative names you could give your functions: 'Y(i+Yy,high,high,0);//turns rail on--------------------------'.

Did you try accessing the multidimensional array directly:

X(e+Xx,cr_0[i][e]);

You can simplify your code greatly by formatting your data structures better:

int y0[3]={0,1,2};
int y1[3]={3,5,6};
int y2[3]={7,8,9};
int y3[3]={10,11,12};
int y4[3]={13,14,0};
int y5[3]={1,2,3};
int Ylist[3][6]={*y0,*y1,*y2,*y3,*y4,*y5};

Can be represented as:

int YList[][3] = {
    {0,1,2},
    {3,5,6},
    {7,8,9},
    {10,11,12},
    {13,14,0},
    {1,2,3}
};

You almost had your usage correct in function Y, the above array is what will help you achieve this. I have also used a switch statement to remove redundant checks.

int *YPtr = Ylist[ e ];

switch( e ){

  case 4:
  case 5:

    left.digitalWrite( YPtr[0],blue );
    left.digitalWrite( YPtr[1],green );
    left.digitalWrite( YPtr[2],red );
    break;

  default:
  
    right.digitalWrite( YPtr[0],blue );
    right.digitalWrite( YPtr[1],green );
    right.digitalWrite( YPtr[2],red );
};

There are lots of things you can do with arrays to improve your sketch.

I understand you read the links I posted above, however it still looks like you have a yet to fully grasp the array concept. Search google for other articles.