Strings to int

i'm trying to convert the strings that i receive in ascii code from a raspberry pi keyboard.

im have the serial receiving and i created this function to convert the strings that come from the serial to use then in a switch statement. switch statements only work with Int type variables.

i get this error in the function :

exit status 1
conversion from 'int' to 'String' is ambiguous

Code:

void conv_String (String intString) {

String val = 'intString';
int result = val.toInt();
return result;
}

Any good idea or code for arduino to convert Strings to Int are welcome

they are simple strings 3 Char more or less they are the ascii codes of the Keyboard coming from the serial like this number "103" up key "108" down key

thank you all.

String val = 'intString';Single quotes for single characters, double quotes for strings.

I can't figure out beyond that what you're trying to do.

Thank you !!! >:( >:( >:(

Trying to convert the name of a String to an integer is not at all the same as converting the contents of the string to an integer.

void conv_String (String intString) {  ////// RETURNING TYPE 'void' MEANS NO VALUE IS RETURNED
  String val = "intString";  ////// THIS CREATES A 'String' CONTAINING THE WORD "intString".
  int result = val.toInt();    ////////  THE WORD "intString" IS NOT A NUMBER SO THIS SETS 'result' TO ZERO
  return result;  //////// WHEN YOUR FUNCTION RETURNS 'void' YOU CAN'T RETURN A VALUE
}

To do what you wanted:

int conv_String (String intString) {  ////// Return an 'int' value
  return intString.toInt();
}

Your function now contains one line. Perhaps you should use "var = myString.toInt();" in place of "var = conv_String(myString);". It would be easier to read since "conv_String()" is not as descriptive as ".toInt()".