Go Down

Topic: expected unqualified-id before 'if' (Read 145 times) previous topic - next topic

sydhalls

Can anyone help me in this regard-

The program compiles and runs without any problem till line 218, however when I added the lines 219-252, I get this "expected unqualified-id before 'if'. What could be wrong???


Code: [Select]
#include <LiquidCrystal.h>
int sump = A0;
int qrt = A1;
int hlf = A2;
int thf = A3;
int ful = A4;
int drun = A5;
int motor = 8;
int bz = 7;
int s;
int d;
int q;
int h;
int t;
int f;
int i;     //motor status flag
int a = 100; //comparison variable
int b = 0; //buzzer flag
int m = 0; //motor flag
int c = 0; //sump flag
int p = 0; //dry run flag



LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void setup()
{

  lcd.begin(16, 4);
  lcd.setCursor(2, 0);
  lcd.print("WATER LEVEL");
  lcd.setCursor(2, 2);
  lcd.print("CONTROLLER");
  delay(3000);
  lcd.clear();
  pinMode(qrt, INPUT);
  pinMode(hlf, INPUT);
  pinMode(thf, INPUT);
  pinMode(ful, INPUT);
  pinMode(sump, INPUT);
  pinMode(motor, OUTPUT);
  pinMode(bz, OUTPUT);
  digitalWrite(bz, LOW);
  pinMode(drun, INPUT);


}
void loop()
{

  i = digitalRead(motor);
  s = analogRead(sump);
  q = analogRead(qrt);
  h = analogRead(hlf);
  t = analogRead(thf);
  f = analogRead(ful);
  d = analogRead(drun);



  if (f > a && t > a && h > a && q > a )
  {
    lcd.setCursor(0, 0);
    lcd.print(char(208));
    lcd.print(char(208));
    lcd.print(char(208));
    lcd.print(char(208));
    lcd.setCursor(0, 1);
    lcd.print(char(208));
    lcd.print(char(208));
    lcd.print(char(208));
    lcd.setCursor(0, 2);
    lcd.print(char(208));
    lcd.print(char(208));
    lcd.setCursor(0, 3);
    lcd.print(char(208));
    lcd.setCursor(5, 0);
    lcd.print("  TANK FULL");
    lcd.setCursor(6, 2);
    lcd.print("          ");
    m = 0;
    b = 0;



  }
  else
  {
    if (f < a && t > a && h > a && q > a)
    {
      lcd.setCursor(0, 0);
      lcd.print("    ");
      lcd.setCursor(0, 1);
      lcd.print(char(208));
      lcd.print(char(208));
      lcd.print(char(208));
      lcd.setCursor(0, 2);
      lcd.print(char(208));
      lcd.print(char(208));
      lcd.setCursor(0, 3);
      lcd.print(char(208));
      lcd.setCursor(5, 0);
      lcd.print("3/4th TANK ");
      lcd.setCursor(6, 2);
      lcd.print("          ");
      b = 0;


    }
    else
    {
      if (f < a && t < a && h > a && q > a)
      {
        lcd.setCursor(0, 1);
        lcd.print("   ");
        lcd.setCursor(0, 2);
        lcd.print(char(208));
        lcd.print(char(208));
        lcd.setCursor(0, 3);
        lcd.print(char(208));
        lcd.setCursor(5, 0);
        lcd.print("1/2   TANK");
        lcd.setCursor(6, 2);
        lcd.print("          ");
        m = 1;
        b = 0;


      }
      else
      {
        if (f < a && t < a && h < a && q > a)
        {
          lcd.setCursor(0, 2);
          lcd.print("  ");
          lcd.setCursor(0, 3);
          lcd.print(char(208));
          lcd.setCursor(5, 0);
          lcd.print("1/4th TANK ");
          lcd.setCursor(6, 3);
          lcd.print("           ");
          lcd.setCursor(6, 2);
          lcd.print("          ");
          m = 1;
          b = 0;


        }
        else if (f < a && t < a && h < a && q < a)
        {
          lcd.setCursor(0, 3);
          lcd.print(" ");
          lcd.setCursor(4, 0);
          lcd.print(" TANK EMPTY");
          m = 1;
          b = 0;
        }

      }
    }
  }

  if (i == HIGH)
  {
    lcd.setCursor(5, 1);
    lcd.print("   PUMP ON");
    lcd.setCursor(5, 3);
    lcd.print("          ");
    lcd.setCursor(5, 2);
    lcd.print("          ");


  }
  else
  {
    lcd.setCursor(5, 1);
    lcd.print("  PUMP OFF");
  }


  if (s > a && m == 1)       // Sump Low Code
  {
    digitalWrite(motor, HIGH);
  }
  if (s < a)
  {
    digitalWrite(motor, LOW);
    lcd.setCursor(5, 2);
    lcd.print("  SUMP LOW");


    c = 1;
  }
  if (s > a)
  {
    c = 0;
  }

  if (m == 0)
  {
    digitalWrite(motor, LOW);
  }
  if (b == 1 || c == 1)
  {
    digitalWrite(bz, HIGH);
    delay(500);
    digitalWrite(bz, LOW);
  }
  else
  {
    digitalWrite(bz, LOW);
  }
  delay(100);
}


if (d > a && m == 1)       // Dry Run Code
{
  digitalWrite(motor, HIGH);
}
if (d < a)
{
  digitalWrite(motor, LOW);
  lcd.setCursor(5, 3);
  lcd.print("  SUMP LOW");


  p = 1;
}
if (d > a)
{
  p = 0;
}

if (m == 0)
{
  digitalWrite(motor, LOW);
}
if (b == 1 || p == 1)
{
  digitalWrite(bz, HIGH);
  delay(500);
  digitalWrite(bz, LOW);
}
else
{
  digitalWrite(bz, LOW);
}
delay(100);
}



GypsumFantastic

All code (with a few exceptions) needs to be inside a function, but the code you added isn't. loop() ends on line 216.

You can fix that by checking how your braces { } match. The IDE's auto-format function is helpful for this.

PaulS

You REALLY need to learn to use functions. There in no excuse for loop() being so long.

If you WERE using functions, it would be perfectly clear where loop() ended, and where you could add another call to another function.
The art of getting good answers lies in asking good questions.

Go Up