int R = 3;
int G = 5;
int B = 6;
String color;
String text = "What color do you want?";
void setup() {
Serial.begin(9600);
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
}
void loop() {
Serial.println(text);
while (Serial.available() == 0) {
}
color = Serial.readString();
if (color == "red" || color == "RED") {
digitalWrite(R, HIGH);
digitalWrite(G, LOW);
digitalWrite(B, LOW);
if (color == "green" || color == "GREEN") {
digitalWrite(R, LOW);
digitalWrite(G, HIGH);
digitalWrite(B, LOW);
}
if (color == "blue" || color == "BLUE") {
digitalWrite(R, LOW);
digitalWrite(G, LOW);
digitalWrite(B, HIGH);
}
if (color == "stop" || color == "STOP") {
digitalWrite(R, LOW);
digitalWrite(G, LOW);
digitalWrite(B, LOW);
}
if (color != "red" && color != "RED" && color != "green" && color != "GREEN" && color != "blue" && color != "BLUE") {
Serial.println("No blinking color!!");
}
if (color == "red" || color == "RED" || color == "green" || color == "GREEN" || color == "blue" || color == "BLUE") {
Serial.print(color);
Serial.println(" of RGB LED is Blinking!!");
}
And when you did that, did you notice that at the bottom of the file, the last line is hanging 'in' by 4 spaces? That's a hint that you've not closed out the {} pairings.
@ruilviana not quite. One if clause is hanging open near the top, but I was hoping the OP would take the hint and review EACH { and figure out where it's mate } should be.
When code compiles without error, it means it's syntax is correct. But it may still be garbage, so at that point, you have to learn to understand what your code is saying. It's like language - you can produce a syntactically correct sentence that says nothing, or nonsense.