how use variable value from string parameter

Hi all
I have a little problem with my code.

I have some int variable (the values are gpio number)

int tap1_1 = 5; // D1 , gpio5
int tap1_2 = 4; //  D2, gpio4

int tap2_1 = 14; //  D5, gpio14
int tap2_2 = 12; //  D6 , gpio12

By http I send a parameter with a name like a variable .
For example I send a parameter "tap1_1"
Now I want the value of that variable (number 5)
How I have to do?
Thanks a lot

You can do this using a series of 'if'. Here is a pseudocode:

if parameter == "tap1_1" value = tap1_1;
else if parameter == "tap1_2" value = tap1_2;
else if parameter == "tap2_1" value = tap2_1;
else if parameter == "tap2_2" value = tap2_2;

When your Arduino program is compiled the names of the variables are replaced by numbers (memory addresses).

You could probably do something along the lines of this pseudo code

char receivedData[] = "tap_1"; // pretend this is the data that has arrived
if (strcmp(receivedData, "tap_1") == 0) {
   myValue = tap_1;
}
else if (strcmp(receivedData, "tap_2") == 0) {
   myValue = tap_2;
}

...R

PS ... I think the example in Reply #1 assumes the use of the String class. That is not a good idea as it can cause memory corruption in the small memory of an Arduino. However the intent is identical to my suggestion.

hi
thanks a lot for your suggest!!!

Thank you very much!!!