Compilation error: expected '}' at end of input

Please help me with this, for my assignment.

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!!");
    }

For every open brace { you need a closing brace }.

Suggest you place { and } on lines by themselves.

In the Arduino IDE, use Ctrl T or CMD T to format your code.

Hi LarryD!

I already did the Crtl + T to auto format

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.

Your code needs more 2 of " } " at end of void loop().

if (color == "red" || color == "RED") { <———<<<<< You need a closing brace to match this.

@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.


I think this solves it right?

You tell us - Wherever you've got {, is the corresponding } in the right place?

Hint - when you hover your cursor/mouse over a {, the IDE hilights the corresponding }, if it exists.

Suggestion - never post another screenshot. Use the Code tags for code in messages, please.

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.

Thank you so much! I got it now

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.