Hi!
I have a Serial connection from which I read characters. After reading 4 characters, I want to compare them to a String.
The message I'm sending is "", but because of start and end characters (explained in the code) the message I want for Arduino to receive after the reading method is "blue", however, it doesn't seem to work.
int i=Serial.read(); // checks the first character
if...// some if statements
else if (i == 60) { // the messages have a "start" character and an "end" character, so the message sent looks like "<blue>", and this else if checks whether or not the first character is '<'
char input[4]; // the message is always 4 characters long
while(j<4){
if(Serial.available()>0){ // reads the message into the buffer
input[j]=Serial.read();
j++;
}
}
i = softSerial.read(); // gets rid of the end character, redundant for now
String s(input);
Serial.println(s);
Serial.println(s.length());
if(s.equals("blue")){
Serial.println("ITS BLUE!");
}
if(strcmp(input, "blue")==0){
Serial.println("ITS BLUE!");
}
}
The serial output from the commands before the if statements is the following:
blue
4
... but none of If statements are "true" unfortunately, even though the message received seems to be correct. How can I fix this?