What's wrong in the second 'if'? 'expected identifier before '(' token' problem

+3 votes
asked Jul 27 by bruno neves teixeira (160 points)
const int BotaoP = 6;
const int BotaoG = 8;
const int ReleSoda =  13;
const int ReleAgua =  9;
const int ReleOleo =  11;
const int ReleMistura =  12;
int NivelSodaP = A0;
int NivelSodaG = A1;
int NivelAguaG = A2;
int NivelAguaP = A3;
int NivelOleoP = A4;
int NivelOleoG = A5;
int EstadoBotaoP = 0;       
int EstadoBotaoG = 0;   

void setup() {
  pinMode(ReleMistura, OUTPUT);  
  pinMode(ReleSoda, OUTPUT);  
  pinMode(ReleAgua, OUTPUT);  
  pinMode(ReleOleo, OUTPUT);     
  pinMode(BotaoP, INPUT);
  pinMode(BotaoG, INPUT);    
  pinMode(NivelAguaP, INPUT);
  pinMode(NivelAguaG, INPUT);
  pinMode(NivelSodaP, INPUT);
  pinMode(NivelSodaG, INPUT);
  pinMode(NivelOleoP, INPUT);
  pinMode(NivelOleoG, INPUT);
}

void loop(){
  EstadoBotaoP = digitalRead(BotaoP);
  EstadoBotaoG = digitalRead(BotaoG);

  if (EstadoBotaoP == HIGH)&&(analogRead(NivelAguaP) > 6)&&(analogRead(NivelSodaP) > 5)&&(analogRead(NivelOleoP) > 5)
{      
    digitalWrite(ReleAgua, LOW);
    delay(3000);
    digitalWrite(ReleAgua, HIGH);
    digitalWrite(ReleSoda, LOW);
    delay(3000);
    digitalWrite(ReleSoda, HIGH);
    digitalWrite(ReleMistura, LOW);
    delay(3000);
    digitalWrite(ReleMistura, HIGH);
    digitalWrite(ReleOleo, LOW);
    delay(3000);
    digitalWrite(ReleOleo, HIGH);
    digitalWrite(ReleMistura, LOW);
    delay(3000);
    digitalWrite(ReleMistura, HIGH);
}
if (EstadoBotaoG == HIGH)&&(analogRead(NivelAguaG) > 6)&&(analogRead(NivelSodaG) > 5)&&(analogRead(NivelOleoG) > 5)
{      
    digitalWrite(ReleAgua, LOW);
    delay(9000);
    digitalWrite(ReleAgua, HIGH);
    digitalWrite(ReleSoda, LOW);
    delay(9000);
    digitalWrite(ReleSoda, HIGH);
    digitalWrite(ReleMistura, LOW);
    delay(9000);
    digitalWrite(ReleMistura, HIGH);
    digitalWrite(ReleOleo, LOW);
    delay(9000);
    digitalWrite(ReleOleo, HIGH);
    digitalWrite(ReleMistura, LOW);
    delay(9000);
    digitalWrite(ReleMistura, HIGH);
}

  else {
    digitalWrite(ReleAgua, HIGH);
    digitalWrite(ReleOleo, HIGH);
    digitalWrite(ReleSoda, HIGH);
    digitalWrite(ReleMistura, HIGH);
  }
}

1 Answer

+1 vote
answered Jul 29 by Peter Minarik (9,500 points)

The syntax of if in C is this:

if ([condition])
    [expression]

In your code, you're missing the parenthesis around the condition seemingly in every if.

So instead of

if (EstadoBotaoP == HIGH)&&(analogRead(NivelAguaP) > 6)&&(analogRead(NivelSodaP) > 5)&&(analogRead(NivelOleoP) > 5)

you must have the whole expression surrounded by parenthesis, like this:

if ((EstadoBotaoP == HIGH)&&(analogRead(NivelAguaP) > 6)&&(analogRead(NivelSodaP) > 5)&&(analogRead(NivelOleoP) > 5))
commented Jul 29 by bruno neves teixeira (160 points)
Thanks a lot! I am feeling stupid, really easy problem lol.
I appreciate.
commented Jul 31 by Peter Minarik (9,500 points)
My pleasure.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...