type conversion and concatenation

Hi all, warning... TOTAL noob to Arduino coming from a Dynamically typed (PHP etc) background......
talking to an 8x8 LED Matrix which works fine and copied some sample code which procedurally goes through every sprite to draw to the matrix ...

sprites are defined ...

byte N1[] = {B00111000,B00111000,B00011000,B00011000,B00011000,B00011000,B00111100,B00111100};
....
byte N10[] = {B01111110,B01111110,B01100110,B01100110,B01100110,B01100110,B01111110,B01111110};
...etc

& I can procedurally draw each

drawScreen(N1);
drawScreen(N2);
...N3 N4 etc

but I want to stick the sprites in an array and iterate through them
in PHP I would... along the lines of...

$sprites=array('N10',N9','N8...etc);
foreach($sprites as $s){
   drawScreen($s);
   $delay+=100;
   //etc
}

i understand that my sprites are declared as 'byte' and assume that thats what drawScreen expects and when iterating through an array of 'N1','N2' etc I am passing a char.

how do I convert 'N1', into the previously declared N1 required by drawScreen() ?

also, I am used to concatenating strings with '.' or '+' but I assume its not so simple in typed languages, e.g.

String mySprite=0;//'0'?
while (x < 10){
   mySprite = 'N' + x;
   drawScreen(mySprite);
  //clearly will not work but how do I do this ?
}

Any help appreciated.

You can use a two-dimensional array or you can use a second array with pointers to the N1/N2 etc arrays; the latter would be more or less the same as what your $sprites=array('N10',N9','N8...etc); does. Two-dimensional arrays might be a little easier.

With regards to the use of String (capital S) in your last snippet, you better forget that it exists if you don't want to pull your hair out later because of unexplainable behaviour. Make use of null terminated character arrays (so called c-strings).

Along the array of pointer lines (untested):

uint8_t N00[] = {B00111000,B00111000,B00011000,B00011000,B00011000,B00011000,B00111100,B00111100};
uint8_t N01[] = {B01111110,B01111110,B01100110,B01100110,B01100110,B01100110,B01111110,B01111110};

uint8_t *spriteArray[] = {N00, N01};
uint8_t numSprites = sizeof(spriteArray) / sizeof(spriteArray[0]);

void setup() {
  uint8_t index;

  for (index = 0; index<numSprites; index++) {
    drawScreen(spriteArray[index]);
    delay(500);
  }

}

void loop() {}

aha, pointers, I think that's what put me off learning C in the first place :wink:

Cheers, I have created a second array of pointers and its cooking with gas, not sure how to do a 2 dimensional array yet but will have a poke around.

byte N1[] = {B00111000,B00111000,B00011000,B00011000,B00011000,B00011000,B00111100,B00111100};
//....
byte N10[] = {B01111110,B01111110,B01100110,B01100110,B01100110,B01100110,B01111110,B01111110};

byte * cdown[10] = { N10 , N9 , N8 , N7 , N6 , N5 , N4 , N3 , N2 , N1};

int z=0; //tried sizeof in loop but no go~


//in main loop...

while(z < 10){
   drawScreen(cdown[z]);
   delay(300);
    z=z+1;
}

So pardoning the pun, thanks for the pointer~

....

Would still be interested in how to concatenate and then create a pointer from that, e.g. in

    for (byte i = 2; i <= 13; i++){
        pinMode(i, OUTPUT);
    }
    pinMode(A0, OUTPUT);
    pinMode(A1, OUTPUT);
    pinMode(A2, OUTPUT);
    pinMode(A3, OUTPUT);
}

we can iterate over the pins to set pinMode easily.

Now I understand I an make my array of pointers, but given say we have... char myChar = 'A' and int myInt = 1
how would I build a pointer reference from that? , again PHP sorry, would be...

$aPin = & $myChar.$myInt
pinMode($aPin,OUTPUT);

Thanks again.

The character 'A' is 0x41 (see e.g. http://www.asciitable.com/).

If you want to access the first element (index 0) of the array, subtract 0x41 to get the number that you can use..

sorry to be dull, I am not getting you, I get A = 0x41 but not sure how I can iterate through A{1-4}

I probably misunderstood, sorry. You will probably be looking at structs and / or classes.

OK,thanks for the input, you and gfvalvo got me going. Cheers.