Hey folks,
I have Uno, and I am trying to do a tutorial, where an input (from Serial monitor) is compared to a string. I did try with tutorial code where string1==string2, or ("something"), but it do not seems to work. Than I tried with ".equals", but still to not result. I am getting this for a second project, but I can not understand why it do not work.
The failure is that If condition is never true. Could you pls have a look on the code, and give any advice?
Thanks!
Here is what I have written:
const int redPin=8;
const int greenPin=10;
const int bluePin=9;
String myColor;
String msg="What color would you like?";
String compareTest = "green";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode (redPin, OUTPUT);
pinMode (greenPin, OUTPUT);
pinMode (bluePin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println (msg);
while (Serial.available()==0);{
//wait
}
myColor=Serial.readString();
Serial.println(myColor);
if (myColor.equals(compareTest)){
digitalWrite (redPin, HIGH);
}
}