# need help to simplify many if,then...!

this is the 3d time i create a thread, sorry about it, it is becouse i am noob on arduino code, but i apriciate your help

lets go on my problem now

``````//here are all letter's patterns:

byte A[8] = {B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte B[8] = {B01111100,B01000010,B01000010,B01111100,B01000010,B01000010,B01000010,B01111100};
byte C[8] = {B00111110,B01000000,B01000000,B01000000,B01000000,B01000000,B01000000,B00111110};
byte D[8] = {B01111100,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B01111100};
byte E[8] = {B01111110,B01000000,B01000000,B01111100,B01000000,B01000000,B01000000,B01111110};
byte F[8] = {B01111110,B01000000,B01000000,B01111100,B01000000,B01000000,B01000000,B01000000};
byte G[8] = {B00111100,B01000010,B01000010,B01000000,B01000111,B01000010,B01000010,B00111100};
byte H[8] = {B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010,B01000010};
byte I[8] = {B00111000,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00111000};
byte J[8] = {B00011100,B00001000,B00001000,B00001000,B00001000,B01001000,B01001000,B00110000};
byte K[8] = {B01000100,B01001000,B01010000,B01100000,B01010000,B01001000,B01000100,B01000010};
byte L[8] = {B01000000,B01000000,B01000000,B01000000,B01000000,B01000000,B01000000,B01111110};
byte M[8] = {B01000100,B10101010,B10010010,B10010010,B10000010,B10000010,B10000010,B10000010};
byte N[8] = {B01000010,B01100010,B01010010,B01001010,B01001010,B01001010,B01000110,B01000010};
byte O[8] = {B00111100,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B00111100};
byte P[8] = {B00111100,B01000010,B01000010,B01000010,B01111100,B01000000,B01000000,B01000000};
byte Q[8] = {B00111100,B01000010,B01000010,B01000010,B01000010,B01000010,B01000110,B00111110};
byte R[8] = {B00111100,B01000010,B01000010,B01000010,B01111100,B01000100,B01000010,B01000010};
byte S[8] = {B00111100,B01000010,B01000000,B01000000,B00111100,B00000010,B01000010,B00111100};
byte T[8] = {B11111110,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000};
byte U[8] = {B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B00111100};
byte V[8] = {B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B00100100,B00011000};
byte W[8] = {B10000010,B10000010,B10000010,B10000010,B10010010,B10010010,B10101010,B01000100};
byte X[8] = {B01000010,B01000010,B00100100,B00011000,B00011000,B00100100,B01000010,B01000010};
byte Y[8] = {B10000010,B01000100,B00101000,B00010000,B00010000,B00010000,B00010000,B00010000};
byte Z[8] = {B01111110,B00000010,B00000100,B00001000,B00010000,B00100000,B01000000,B01111110};

//these are the variables that some of previous varaibles (A...Z) will be copy to later:

byte pat_1[8] = {B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte pat_2[8] = {B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte pat_3[8] = {B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte pat_4[8] = {B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte pat_5[8] = {B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte pat_6[8] = {B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};

//here are the variables that will coming via serial communication

char input_1="T";
char input_2="H";
char input_3="O";
char input_4="M";
char input_5="A";
char input_6="S";
``````

What i need to do now? to store in pat_1,pat_2,pat_3,pat_4,pat_5,pat_6 variables the contest of A..Z variables acordinary to input varaibles.

i know a way to do this like that.....(forget the syntax error, i am writing simply to be easier to understand)

//phase 1 (checking for input_1) if input_1= 'A' then pat_1=A if input_1= 'B' then pat_1=B if input_1= 'B' then pat_1=B .... ... if input_1= 'Z' then pat_1=Z //phase 1 (checking for input_1) if input_1= 'A' then pat_1=A if input_1= 'B' then pat_1=B if input_1= 'B' then pat_1=B .... ... if input_1= 'Z' then pat_1=Z //phase 2 (checking for input_2) if input_2= 'A' then pat_2=A if input_2= 'B' then pat_2=B if input_2= 'B' then pat_2=B .... ... if input_2= 'Z' then pat_2=Z //and so until checking all inputs with all patterns!!!! :o is there any other solution for this?

I think there was one posted in one of your other threads, using an index and some arithmetic.

damn, i dont get it :-/

i dont get it

Did you try it?

Try this: (uncompiled, untested)

``````byte* index [] = {A, B, C, D, E, F, G, H, I, J....};

byte* myLetter = index [myLetter - 'A'];
``````

Does that get you anywhere?

error: invalid conversion from 'byte*' to 'byte

Oops, should have been:`byte* myPattern = index [myLetter - 'A'];`

Sorry. [smiley=embarassed.gif]

byte* index = {A, B, C, D, E, F, G, H, I, J};

here it gives the error

No, no problem here.

maybe something else in my code create this issue on this line

Maybe. In fact, most likely.

(At this point, you post your code)

ok…but i dont know if you want to read this crazy code…

``````int LatchPin = 6;
int DataPin = 7;
int ClockPin = 8;

int R_LatchPin = 3;
int R_ClockPin = 4;
int R_DataPin = 2;

int i;

int row=0;
//x,y for the loop
int x;
int y;

byte A[8] = {B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte B[8] = {B01111100,B01000010,B01000010,B01111100,B01000010,B01000010,B01000010,B01111100};
byte C[8] = {B00111110,B01000000,B01000000,B01000000,B01000000,B01000000,B01000000,B00111110};
byte D[8] = {B01111100,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B01111100};
byte E[8] = {B01111110,B01000000,B01000000,B01111100,B01000000,B01000000,B01000000,B01111110};
byte F[8] = {B01111110,B01000000,B01000000,B01111100,B01000000,B01000000,B01000000,B01000000};
byte G[8] = {B00111100,B01000010,B01000010,B01000000,B01000111,B01000010,B01000010,B00111100};
byte H[8] = {B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010,B01000010};
byte I[8] = {B00111000,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00111000};
byte J[8] = {B00011100,B00001000,B00001000,B00001000,B00001000,B01001000,B01001000,B00110000};
byte K[8] = {B01000100,B01001000,B01010000,B01100000,B01010000,B01001000,B01000100,B01000010};
byte L[8] = {B01000000,B01000000,B01000000,B01000000,B01000000,B01000000,B01000000,B01111110};
byte M[8] = {B01000100,B10101010,B10010010,B10010010,B10000010,B10000010,B10000010,B10000010};
byte N[8] = {B01000010,B01100010,B01010010,B01001010,B01001010,B01001010,B01000110,B01000010};
byte O[8] = {B00111100,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B00111100};
byte P[8] = {B00111100,B01000010,B01000010,B01000010,B01111100,B01000000,B01000000,B01000000};
byte Q[8] = {B00111100,B01000010,B01000010,B01000010,B01000010,B01000010,B01000110,B00111110};
byte R[8] = {B00111100,B01000010,B01000010,B01000010,B01111100,B01000100,B01000010,B01000010};
byte S[8] = {B00111100,B01000010,B01000000,B01000000,B00111100,B00000010,B01000010,B00111100};
byte T[8] = {B11111110,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000};
byte U[8] = {B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B00111100};
byte V[8] = {B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B00100100,B00011000};
byte W[8] = {B10000010,B10000010,B10000010,B10000010,B10010010,B10010010,B10101010,B01000100};
byte X[8] = {B01000010,B01000010,B00100100,B00011000,B00011000,B00100100,B01000010,B01000010};
byte Y[8] = {B10000010,B01000100,B00101000,B00010000,B00010000,B00010000,B00010000,B00010000};
byte Z[8] = {B01111110,B00000010,B00000100,B00001000,B00010000,B00100000,B01000000,B01111110};

byte pat_1[8] = {B00000000,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte pat_2[8] = {B00000000,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte pat_3[8] = {B00000000,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte pat_4[8] = {B00000000,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte pat_5[8] = {B00000000,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};
byte pat_6[8] = {B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010};

char input_1;
char input_2;
char input_3;
char input_4;
char input_5;
char input_6;

#define exp_pat_1   {pat_1[1],pat_1[2],pat_1[3],pat_1[4],pat_1[5],pat_1[6],pat_1[7],pat_1[8]}
#define exp_pat_2   {pat_2[1],pat_2[2],pat_2[3],pat_2[4],pat_2[5],pat_2[6],pat_2[7],pat_2[8]}
#define exp_pat_3   {pat_3[1],pat_3[2],pat_3[3],pat_3[4],pat_3[5],pat_3[6],pat_3[7],pat_3[8]}
#define exp_pat_4   {pat_4[1],pat_4[2],pat_4[3],pat_4[4],pat_4[5],pat_4[6],pat_4[7],pat_4[8]}
#define exp_pat_5   {pat_5[1],pat_5[2],pat_5[3],pat_5[4],pat_5[5],pat_5[6],pat_5[7],pat_5[8]}
#define exp_pat_6   {pat_6[1],pat_6[2],pat_6[3],pat_6[4],pat_6[5],pat_6[6],pat_6[7],pat_6[8]}

byte row_scan [8]= {B00000001,B00000010,B00000100,B00001000,B00010000,B00100000,B01000000,B10000000};

const int numPatterns = 6;//this is the number of patterns you want to display
byte patterns[6][10]= {exp_pat_1,exp_pat_2,exp_pat_3,exp_pat_4,exp_pat_5,exp_pat_6};// the patterns orderPat

void setup(){
pinMode(DataPin,OUTPUT);
pinMode(ClockPin,OUTPUT);
pinMode(LatchPin,OUTPUT);

pinMode(R_DataPin,OUTPUT);
pinMode(R_ClockPin,OUTPUT);
pinMode(R_LatchPin,OUTPUT);

Serial.begin(9600);

}

void loop(){
byte index [] = {A, B, C, D, E, F, G, H, I, J};
byte myPattern = index [myLetter - 'A'];

display_pattern(110);// calls for the display_pattern function and says that int loop = 15(if you do more loop the pattern whould scrrol slower).

}

void display_pattern(int loops)//int loop acts like a delay, it take 8 mSecands to scan all of the rows so int loops = 15 is a good time for it

{
for(x=0;x<numPatterns-2;x++){ // loop over the patterns
for (int z=0;z<8;z++){ //scrolls one bite at a time
for(int t=0;t<loops;t++){// the delay we get with loops
for(y=0;y<10;y++){// loops over the array of bytes
byte scanner = row_scan[row];
row=row+1;
if (row==8) {row=0;}

digitalWrite(R_LatchPin, 0);
shiftOut(R_DataPin, R_ClockPin,MSBFIRST,scanner);
digitalWrite(R_LatchPin, 1);

byte temp_1 = patterns[x][y];
byte temp_2=  patterns[x+1][y];
byte temp_3=  patterns[x+2][y];

digitalWrite(LatchPin, 0);
shiftOut(DataPin, ClockPin,MSBFIRST,((temp_1<<z)+(temp_2>>8-z)));//writes digital outputs, Z is for how much bites it need to scroll [ch913][ch929][ch921][ch931][ch932][ch917][ch929][ch919] [ch928][ch923][ch917][ch933][ch929][ch913]
shiftOut(DataPin, ClockPin,MSBFIRST,((temp_2<<z)+(temp_3>>8-z)));//writes digital outputs, Z is for how much bites it need to scroll [ch916][ch917][ch926][ch921][ch913] [ch928][ch923][ch917][ch933][ch929][ch913]
digitalWrite(LatchPin, 1);

delayMicroseconds(800);

digitalWrite(LatchPin, 0);
shiftOut(DataPin, ClockPin,MSBFIRST,0);
shiftOut(DataPin, ClockPin,MSBFIRST,0);
digitalWrite(LatchPin, 1);

}
}
}
}
}
``````

byte* index [] = {A, B, C, D, E, F, G, H, I, J};

here it gives the error

But that's not what's in the sketch.

what you mean?

I mean that the line you said was in error in your earlier reply was not the same line that was in your sketch.

I think you've bitten off a bit too much here - have you tried any of the examples?

i am trying, this forum helped me very much. I need to study more

thanks alot