Hello,
I am self-taught, so please forgive me if this is a dumb question...
After seaching the forum and StackOverflow I couldn't find a answer (maybe because I didn't use the proper terminology):
I have multiple 2-D-arrays and want to grab data from them depending on what I input.
I've extracted the important code-parts and made them generic:
String arraylist[3] = {"array_a", "array_b", "array_c"};
int array_a[2][4] = {{255, 240, 270, 310},{390, 210, 210, 240}};
int array_b[2][1] = {{280},{1080}};
int array_c[2][3] = {{255, 300, 280},{360, 1200, 180}};
int data1;
String activearray = "";
String text = ""; //This is changed by input in the full code
void selectarray(){
for (int pi = 0, pi < sizeof(arraylist)/sizeof(arraylist[0], pi++)){
if (text == arraylist[pi]){
activearray = arraylist[pi];
Serial.println("Array "+activearray+" selected");
data1 = activearray[0][1]; //This is where the Problem is
}
}
}
Is there an easy way to make the arduino handle the string I give him as an name of an array? Inspired by easy solutions to similar problems with String and int I tried things like
data1 = int[][](activearray)[0][1];
data1 = array(activearray)[0][1];
but (i guess for more skilled this is obvious) these did not work.
Maybe a different approach with an array-enum would be better instead of my String-array and then access the arrays through the enum (but then how to Serial.print them?)?
Help is greatly appreciated
Thanks for your time