I am currently trying to write a program that receives a message from the serial communications window, puts it together, interprets it, and responds accordingly. So far, however, I haven't gotten past the second step. The reason being that none of the functions for the String class appear to be working. Here is my (rather brief) code:
void setup(){
Serial.begin(9600); //Begin serial communications
}
void loop(){
int mesLength=Serial.available(); //Determines the length of the received message
if (mesLength>0){ //Continues if a message was received
String str1=String(char(Serial.read())); //Converts first value to a char, then to a String
for (int i=0; i<=mesLength; i++){ //The for loop is to combine and convert all read values into one complete String
String str2=String(char(Serial.read())); //Converts next value to a char, then to a String
str1.concat(str1, str2); //Adds str2 to str1, both together becoming str1
}
Serial.println(str1); //Prints str1 (the complete message)
}
}
Unfortunately, this code brings up an error:
no matching function for call to 'String::concat(String&, String&)'
To make up for this, I changed one small piece my code:
str1+=str2;
The good news is: no error messages! The bad news: it doesn't print what I want, which is a complete string. I typed in 'Hello' (without quotation marks) using the modified code and this is what I got:
Hÿÿ
eÿÿ
lÿÿ
lÿÿ
oÿÿ
Although its a shame that this last attempt didn't work, the bigger problem is that none of the String functions are working. I typed in all of them (including concat()) and not one changed color. The only one that the IDE seems to recognize is 'String' itself.
Why is that? Can I fix the problem? Am I doing something wrong? If it helps, I am using an Arduino Uno R3 and my IDE version is 1.0.5. Thanks!