How can I print an error Msg. at the end of each else if statement? When I put a Serial.print (Msg3); command after any of the else it statements the ERROR Msg prints No matter what color I pick even if the color is spelled right.
int ledR=8;
int ledG=9;
int ledB=10;
int motspd=3;
String Msg1= "What color do you want ";
String Msg2= "You picked: ";
String Msg3="ERROR";
String Yourcolor;
int dt=3000;
void setup() {
// put your setup code here, to run once:
Serial.begin (9600);
pinMode (ledR,OUTPUT);
pinMode (ledG,OUTPUT);
pinMode (ledB,OUTPUT);}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite (ledR,LOW);
digitalWrite (ledG,LOW);
digitalWrite (ledB,LOW);
Serial.println(Msg1);
while (Serial.available()==0);{
}
Yourcolor=Serial.readString();
if (Yourcolor=="red" || Yourcolor=="Red" || Yourcolor=="RED"){
digitalWrite(ledR,HIGH);
// digitalWrite(ledG,LOW);
// digitalWrite(ledB,LOW);
}
else if (Yourcolor!="red" || Yourcolor!="Red" || Yourcolor!="RED"){
Serial.println(Msg3);
}
if (Yourcolor=="green" ||Yourcolor=="Green" ||Yourcolor=="GREEN"){
//digitalWrite(ledR,LOW);
digitalWrite(ledG,HIGH);
//digitalWrite(ledB,LOW);
}
//else if (Yourcolor!="green" || Yourcolor!="Green" || Yourcolor!="GREEN"){
//digitalWrite(ledG,LOW);}
if (Yourcolor=="blue" ||Yourcolor=="Blue" ||Yourcolor=="BLUE"){
//digitalWrite(ledR,LOW);
// digitalWrite(ledG,LOW);
digitalWrite(ledB,HIGH);}
// else if (Yourcolor!="blue" ||Yourcolor!="Blue" ||Yourcolor!="BLUE"){
// digitalWrite(ledB,LOW);}
Serial.print (Msg2);
Serial.println (Yourcolor);
delay(dt);
}