expected declaration before '}' token

Hi,

I was trying to upload some code to my arduion and keep getting this error message:

My_Watlow:54:1: error: expected declaration before '}' token

 }

 ^

exit status 1
expected declaration before '}' token

Here is the code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <max6675.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
int thermoDO = 7;
int thermoCS = 5;
int thermoCLK = 6;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int potpin = 0;
int val;


void setup() {
  pinMode (9, OUTPUT);
  pinMode (10, OUTPUT);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3D);
  display.display();
  display.clearDisplay();
  delay(2500);
}

void loop() {
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.print("F= ");
  display.println(thermocouple.readFahrenheit());
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 20);
  display.print("Set= ");
  display.println(val);
  display.display();
  delay(2000);
  display.clearDisplay();
  val = analogRead(potpin);
  if (thermocouple.readFahrenheit() > val) {
    digitalWrite(10, LOW);// set pin 10 LOW
  } else {
    digitalWrite(10, HIGH);// set pin 10 HIGH
    if (thermocouple.readFahrenheit() > val) {
      digitalWrite(9, HIGH);
      delay(5000);
      digitalWrite(9, LOW);
    } else {
      digitalWrite(9, LOW);
      delay(1000);
    }
  }
}
}
}

Count your curly braces. There must be EXACTLY the same number of '{'s as '}'s.

Somewhat a duplicate of what gfvalvo replied while I was writing this, but there is some extra info so I'll post it anyway:

A very useful troubleshooting tool is to do a Tools > Auto Format on your code and then look at the resulting indentation to make sure it matches your intended program structure. I see you have already done an Auto Format on your code (thanks!) so you only need to look at it. Everything looks fine until we get to the last couple lines:

  }
}
}
}

This indentation (actually lack of) is a clear sign that you have more closing braces than you do opening braces. They should always be matched. So the solution is to simply remove the extra closing braces.

Looks like there are 2 extra }} thingies.

If you put the cursor next to the ( thingy or the ) thingy or the thingy { or the } thingy, the IDE will show the matching thingy.

Makes it easy to find the extra thingies.

I also think there is a logic error in the handling of pin 10 leading to the {} mess.

I think the else statement calls for a one line execution and there is no need for an opening/closing bracket.

Or, if stylistically you always use {} to open and close a conditional execution statement even if it is a one line execution, then you need to add a }.

if (thermocouple.readFahrenheit() > val)
{
  digitalWrite(10, LOW);// set pin 10 LOW
}
else
  //{
  digitalWrite(10, HIGH);// set pin 10 HIGH

or

if (thermocouple.readFahrenheit() > val)
{
  digitalWrite(10, LOW);// set pin 10 LOW
}
else
{
  digitalWrite(10, HIGH);// set pin 10 HIGH
}