commented out a line and functions "are not in this scope"

HI guys. I’m building a freezer temp controller for a friend’s home brew system…

I have it all on a bread board and its working almost like it should. I’m having an issue with // int relayPin;
(its not staying HIGH as commanded, its only staying HIGH for a short time)

you will see in my code that if there is a temp difference of X then turn on relay pin and nested in that “IF” statement is another if statement to turn it off at a temp of Y. (line 76 and 77)

The code as is compiles fine and everything else works like it should.
I attempted to comment out line 76 and 77 to see if there was some type of issue with the value settings on that “IF” statement…
when i commented out the lines, it no longer compiled. It told me that neither of my functions have been declared in this scope… the functions have nothing to do with what i commented out (at least to my knowlege)

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

int SensorPin = A1;
int SetPin = A3 ;

float sensorVal;
int setVal;

float sensorTemp;
int setTemp;

int tempDiffPos;
int tempDiffNeg;
int count;

int LED_B = 9;    // PWM capable
int LED_G = 10;   // PWM capable
int LED_R = 11;   // PWM capable
int relayPin = 3; // PWM capable
const byte relaySensor = 4;
const byte button = 2;

void setup() {

  pinMode(LED_B, OUTPUT);
  pinMode(LED_G, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(SetPin, INPUT);
  pinMode(SensorPin, INPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(relaySensor, INPUT);
  pinMode(button, INPUT);
  count = 0;
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print(" !  Mmmmmmmm  ! ");
  lcd.setCursor(0, 1);
  lcd.print("  KOEL'D  BEER  ");
  delay(2000);
  lcd.clear();
}

void loop() {
  // put your main code here, to run repeatedly:
  sensorVal = analogRead(SensorPin);
  sensorTemp = map (sensorVal, 410.00, 754.00, 28.00, 80.00);   // sensor

  tempDiffPos = (sensorTemp - setTemp);
  tempDiffNeg = (setTemp - sensorTemp);

  while (digitalRead(button) == HIGH) {
    SetTempVal();
  }

  lcd.setCursor(0, 0);
  lcd.print("SENSOR    ");
  lcd.setCursor(10, 0);
  lcd.print(sensorTemp);
  lcd.setCursor(0, 1);
  lcd.print("  SET     ");
  lcd.setCursor(10, 1);
  lcd.print(setTemp);

  //**************************************************  BLUE FUNCTION  **********************************************
  // turn cooling on and check cooling circuit in the mains power.  if an issue is found in the mains power, log the fault and display fault

  if (sensorTemp - setTemp > 1.3) {
    digitalWrite(LED_G, LOW);
    digitalWrite(LED_R, LOW);
    digitalWrite(relayPin, HIGH);
    delay(100);

    if (tempDiffNeg = 1) {            // issue when commented out
      digitalWrite(relayPin, LOW);    //   
    }

    if (digitalRead(relaySensor) == LOW) {
      count++;
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("     SYSTEM     ");
      lcd.setCursor(0, 1);
      lcd.print("     FAULT!      ");
      for (int i = 0; i <= count; i++) { // opperate pulse per count value
        countDisplay(); // pulse LED
      }
      delay(1250);
    }
    while (digitalRead(relaySensor) == HIGH ) {
      for (int b = 15; b <= 255; b++) {
        analogWrite(LED_B, b);
        delay(5);
      }
      for (int b = 255; b >= 15; b--) {
        analogWrite(LED_B, b);
        delay(5);
      }
    }
  }

  //************************************************  GREEN FUNCTION **********************************************

  // if statement uses digital read so that green function doesnt clash with blue function.  also display fault log if applicable

  if (((tempDiffPos <= 1.35) && digitalRead(relaySensor) == LOW) || ((tempDiffNeg >= 1.35) && digitalRead(relaySensor) == LOW))  {
    digitalWrite(LED_B, LOW);
    digitalWrite(LED_R, LOW);

    for (int g = 15; g <= 255; g++) {
      analogWrite(LED_G, g);
      delay(5);
    }
    for (int g = 255; g >= 15; g--) {
      analogWrite(LED_G, g);
      delay(5);
    }
    if (count > 0) {
      for (int i = 0; i <= count; i++) { // opperate pulse per count value
        countDisplay(); // pulse LED
      }
      delay(1250);
    }
  }

  //********************************************* RED FUNCTION ********************************************
  // display fault log if applicable and show there is no cooling action taking place

  if (tempDiffNeg >= 1.36) {
    digitalWrite(LED_B, LOW);
    digitalWrite(LED_G, LOW);
    if (count > 0) {
      for (int i = 0; i <= count; i++) { // opperate pulse per count value
        countDisplay(); // pulse LED
      }
      delay(1250);
    }
    for (int r = 15; r <= 255; r++) {
      analogWrite(LED_R, r);
      delay(5);
    }
    for (int r = 255; r >= 15; r--) {
      analogWrite(LED_R, r);
      delay(5);
    }
  }

  //  ****************************************  DEFAULT TO OFF  ****************************************

  else {
    digitalWrite(relayPin, LOW);
    digitalWrite(LED_B, LOW);
    digitalWrite(LED_G, LOW);
    digitalWrite(LED_R, LOW);
  }
}

// *****************************************  FAULT COUNTER FUNCTION  ***********************************

void countDisplay() {
  digitalWrite(LED_R, HIGH);
  delay(350);
  digitalWrite(LED_R, LOW);
  delay(350);
}

int SetTempVal() {
  // lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("  KOEL'D  BEER  ");
  lcd.setCursor(0, 1);
  lcd.print("SET        ");
  setVal = analogRead(SetPin);
  setTemp = map (setVal, 11.0, 880.0, 28.0, 80.0);   // pot
  lcd.setCursor(12, 1);
  lcd.print(setTemp);
  return setTemp;
}
    if (tempDiffNeg = 1) {            // issue when commented out ->> Yeah, you removed an opening brace
      digitalWrite(relayPin, LOW);    //   
    }   // -> But left behind a closing brace.

and this

   if (tempDiffNeg = 1) {

is not a comparison (==). It is an assignment (=).

Pete

hahahaha wow. that was easy. I changed it as suggested and it compiles fine. Thank you... off to the work bench again.

A very helpful troubleshooting tool is the Arduino IDE's Tools > Auto Format feature. If you do an Auto Format and then compare the resulting indentation to your intended program structure, it will quickly point you to where there is a missing or extra brace.

Another useful feature of the Arduino IDE is that when you place the cursor next to one bracket, it puts a box around the matching bracket. If the cursor is next to the closing bracket and the opening bracket is off the screen then it will show the opening bracket line in a tool tip after a short delay.

Yes, usually when you miss a bracket the first thing in the errors is the “expected something or other” not the “was not declared in this scope”

Another useful feature of the Arduino IDE is that when you place the cursor next to one bracket, it puts a box around the matching bracket

It used to be even nicer in that when you double clicked after one bracket the code inside the matching bracket was highlighted. Sadly this was removed, either accidentally or on purpose, perhaps when code folding was added.

That feature was lost when they changed to using the RSyntaxTextArea editor in Arduino IDE 1.6.5. Certainly the reason for changing to RSyntaxTextArea was not because they wanted to get rid of the highlighting feature. Probably they didn't even consider that as a factor in the decision. It's quite likely the Arduino developers didn't even know about the highlighting feature. The loss of the feature was only reported after the change had been made: https://github.com/arduino/Arduino/issues/3387 I believe the feature would now need to be pushed to the RSyntaxTextArea project, so it's seen as an upstream problem. Unfortunately there seems to have been a misunderstanding that caused the lead developer at that time to think there had already been a feature request submitted to the RSyntaxTextArea repository but after I did some investigation I found that feature request was talking about something completely different (but also very much needed).

A thing I've found useful is

void my_function() {
  if (something==somevalue) {

    ...
    if (something(else)) {
      doing_some(stuff)
    } // finished if (something(else)
    ...
    doing(otherstuff)
    ...
  } // finished if (something(else))
} // finished my_function()

I do something similar with preprocessor conditionals but I think that, between indentation and the matched bracket highlighting feature, there's no point in doing it for braces.

pert:
I do something similar with preprocessor conditionals but I think that, between indentation and the matched bracket highlighting feature, there’s no point in doing it for braces.

Heck, I need all the help I can get

If it's helpful enough to be worth the time it takes you to write the comments, I say go for it.

One thing to keep in mind, the comments document your intent for the brace, whereas the indentation from Auto Format and the matching bracket highlight show what the brace is actually doing. Those may both be useful to know, but they are not necessarily the same thing.

pert: Those may both be useful to know, but they are not necessarily the same thing.

True enough, but they have another useful benefit:

They help me keep track of where I'm at in the code. (I also get lost easily)

Even better (my opinion) is to put each opening and closing brace on its own line so that the opening and closing braces are vertically aligned giving even more visual clues and obvious misalignment of the code if a brace is missing

void my_function()
{
  if (something == somevalue)
  {
    ...
    if (something(else))
    {
      doing_some(stuff)
    } // finished if (something(else)
    ...
    doing(otherstuff)
    ...
  } // finished if (something(else))
} // finished my_function()

Change the Auto Format options and it will do it for you.

Thanks for the input guys.... I do have another question though. I'm trying to set the temp sensor "calibration" via map function. I taped a thermal coupler from my fluke 233 to the temp sensor and placed them both in the freezer. the fluke said 18 degrees F and the sensor had an output of 2.034vdc or 416 on the ADC I then placed the sensor outside the freezer and waited for about 15min... the fluke said 76 degrees F and the sensor output was 3.86vdc or 790 on the ADC. I mapped tried mapping (416, 790, 18, 76) I placed the sensor and fluke sensor in the fridge and they are showing a 4 degree F difference (fluke says 32 and Arduino says 36) (when fluke is in the 50's or 60's the Arduino has been witnessed to be 8 degrees off) (the arduino is always higher than the fluke)

the sensor circuit is a basic voltage diveder. R1 is the sensor (B3950, with stainless steal cover) R2 is 24K ohms.

How can i get a more accurate reading in the middle of the spectrum??