Suggest parentheses around comparison in operand of '|' [-Werror=parentheses]

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "EEPROM.h"
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
long duration, inches;
int lvl,m,sm,fulllvl,lowlvl,lowset,mode,dly,inch;
bool st,out;
void setup()
{
pinMode(2, INPUT);
pinMode(4, OUTPUT);
pinMode(15, OUTPUT);
pinMode(34, INPUT);
pinMode(35, INPUT);
Serial.begin(9600);
EEPROM.begin(4);
//-----------
// initialize the LCD
lcd.begin();

// Turn on the blacklight and print a message.
lcd.backlight();
lcd.print("TANK LEVEL: 100%");

lcd.setCursor(0, 1);
lcd.print("MODE:A OUT:OFF");
mode=EEPROM.read(0);
lowset=EEPROM.read(1);
fulllvl=EEPROM.read(2);
lowlvl=EEPROM.read(3);
if(mode>1)mode=0;
if(lowset<10)lowset=10;
if(lowset>90)lowset=10;
if(fulllvl>100)lowlvl=0;
if(lowlvl>120)lowlvl=1;

}

void loop()
{
dly++;
digitalWrite(4, LOW);
delayMicroseconds(2);
digitalWrite(4, HIGH);
delayMicroseconds(10);
digitalWrite(4, LOW);
duration = pulseIn(2, HIGH);
inches = microsecondsToInches(duration);
inch=inches-fulllvl;
lvl=(((lowlvl-inch))*100)/(lowlvl);
if(lvl<0)lvl=0;
if(lvl>100)lvl=100;
//----------------------------------
if( digitalRead(35)&digitalRead(34))st=0;
if( !digitalRead(34)&!st){
st=1;
if(m==0){m=1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" MODE ");}
else if(m==2|m==1){
lcd.setCursor(0, 1);
lcd.print(" ");
if(sm==0){sm=1;

}
else if(sm==1){sm=0;
if(m==1) EEPROM.write(0, mode);
else EEPROM.write(1, lowset);
EEPROM.commit();

}

}
else if(m==3){
fulllvl=inches;
lcd.setCursor(7, 1);
lcd.print(fulllvl);
EEPROM.write(2, fulllvl);
EEPROM.commit();
delay(1000);
lcd.setCursor(0, 1);
lcd.print(" ");
}

else if(m==4){

lowlvl=inch;
if(lowlvl<1)lowlvl=1;
lcd.setCursor(7, 1);
lcd.print(lowlvl);
EEPROM.write(3, lowlvl);
EEPROM.commit();
delay(1000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
else if(m==5){
m=0;

lcd.setCursor(0, 0);
lcd.print("TANK LEVEL: 100%");
lcd.setCursor(0, 1);
lcd.print("MODE:A OUT:OFF");
}

}
if( !digitalRead(35)&!st){
st=1;
if(m==0){
if(mode==1&lvl<99){out=!out; delay(500); }
}
else{
if(sm==0){m++;
if(m>5)m=1;
lcd.setCursor(0, 0);
if(m==1)lcd.print(" MODE ");
if(m==2)lcd.print(" LOW LEVEL ");
if(m==3)lcd.print(" CALIBRATE FULL");
if(m==4)lcd.print(" CALIBRATE EMPTY");
if(m==5)lcd.print(" EXIT ");
}else{
if(m==1)mode++;
if(m==2)lowset+=10;
if(mode>1)mode=0;
if(lowset>90)lowset=10;
}
} }
//---------------------

//-------------
if(dly>30){dly=0;
Serial.print("level ");
Serial.print(lvl);
Serial.print(" inch ");
Serial.println(inches);
if(lvl>99)out=0;
else if(mode==0&lvl<lowset)out=1;

if(m==0) {
//------------------------------
lcd.setCursor(12, 0);
if(lvl<100)lcd.print(" ");
if(lvl<10)lcd.print(" ");
lcd.print(lvl);
lcd.setCursor(5, 1);
if(mode==0)lcd.print("ATO");
else if(mode==1)lcd.print("MAN");

lcd.setCursor(13, 1);
if(out)lcd.print("ON ");
else lcd.print("OFF");
}
else if(sm==1){
if(m==1) {
lcd.setCursor(6, 1);
if(mode==0)lcd.print("ATO");
else if(mode==1)lcd.print("MAN");

}else if(m==2){
lcd.setCursor(7, 1);
lcd.print(lowset);

}

}
}
//----------------------------
digitalWrite(15,out);
//----------------
delay(10);
}
long microsecondsToInches(long microseconds) {
return microseconds / 74 / 2;
}

this code

What about it?

It looks like you tried to use the correct formatting, :+1:
but it didn't quite work out. :frowning_face:

Please do try again.
This will help: "How to get the best out of this forum" - in particular, " Posting code and common code problems"

Please also post the full warning message - copy & paste, as for the code.

1 Like

Typically the warning is an indication that what you coded may not what you meant due to precedence. In this case you probably meant || (logical or) rather than | (bitwise or).

full code change correction sir plz upload youvar comment

this code correction but new error
Compilation error: expected ';' before 'if'

I don't see a change.

And please, never ever change posted code after people have commented on it. Just post your updated code in a new reply.

1 Like

Please read and follow post #3 !!!
Never post code as pictures.

1 Like

post #3 code correction but new error
expected ';' before 'if'

So post the code that's giving that error - using the <CODE/> button, as described.

Also post all the text from the 'Output' window - as for code: copy & paste the text and use the <CODE/> button.

The instructions are all in post #3.

There is no code in post #3. There is however the suggestion to read a topic how you should post code (using code tags).

For errors, right click in the output window, click 'copy all' and paste here in a reply (again using code tags).

[quote="karthikshop, post:1, topic:1177268, full:true"]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "EEPROM.h"
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
long duration, inches;
int lvl,m,sm,fulllvl,lowlvl,lowset,mode,dly,inch;
bool st,out;
void setup()
{
pinMode(2, INPUT);
pinMode(4, OUTPUT);
pinMode(15, OUTPUT);
pinMode(34, INPUT);
pinMode(35, INPUT);
Serial.begin(9600);
EEPROM.begin(4);
//-----------
// initialize the LCD
lcd.begin();

// Turn on the blacklight and print a message.
lcd.backlight();
lcd.print("TANK LEVEL: 100%");

lcd.setCursor(0, 1);
lcd.print("MODE:A OUT:OFF");
mode=EEPROM.read(0);
lowset=EEPROM.read(1);
fulllvl=EEPROM.read(2);
lowlvl=EEPROM.read(3);
if(mode>1)mode=0;
if(lowset<10)lowset=10;
if(lowset>90)lowset=10;
if(fulllvl>100)lowlvl=0;
if(lowlvl>120)lowlvl=1;

}

void loop()
{
dly++;
digitalWrite(4, LOW);
delayMicroseconds(2);
digitalWrite(4, HIGH);
delayMicroseconds(10);
digitalWrite(4, LOW);
duration = pulseIn(2, HIGH);
inches = microsecondsToInches(duration);
inch=inches-fulllvl;
lvl=(((lowlvl-inch))*100)/(lowlvl);
if(lvl<0)lvl=0;
if(lvl>100)lvl=100;
//----------------------------------
if( digitalRead(35)&digitalRead(34))st=0;
if( !digitalRead(34)&!st){
st=1;
if(m==0){m=1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" MODE ");}
else if(m==2|m==1){
lcd.setCursor(0, 1);
lcd.print(" ");
if(sm==0){sm=1;

}
else if(sm==1){sm=0;
if(m==1) EEPROM.write(0, mode);
else EEPROM.write(1, lowset);
EEPROM.commit();

}

}
else if(m==3){
fulllvl=inches;
lcd.setCursor(7, 1);
lcd.print(fulllvl);
EEPROM.write(2, fulllvl);
EEPROM.commit();
delay(1000);
lcd.setCursor(0, 1);
lcd.print(" ");
}

else if(m==4){

lowlvl=inch;
if(lowlvl<1)lowlvl=1;
lcd.setCursor(7, 1);
lcd.print(lowlvl);
EEPROM.write(3, lowlvl);
EEPROM.commit();
delay(1000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
else if(m==5){
m=0;

lcd.setCursor(0, 0);
lcd.print("TANK LEVEL: 100%");
lcd.setCursor(0, 1);
lcd.print("MODE:A OUT:OFF");
}

}
if( !digitalRead(35)&!st){
st=1;
if(m==0){
if(mode==1&lvl<99){out=!out; delay(500); }
}
else{
if(sm==0){m++;
if(m>5)m=1;
lcd.setCursor(0, 0);
if(m==1)lcd.print(" MODE ");
if(m==2)lcd.print(" LOW LEVEL ");
if(m==3)lcd.print(" CALIBRATE FULL");
if(m==4)lcd.print(" CALIBRATE EMPTY");
if(m==5)lcd.print(" EXIT ");
}else{
if(m==1)mode++;
if(m==2)lowset+=10;
if(mode>1)mode=0;
if(lowset>90)lowset=10;
}
} }
//---------------------

//-------------
if(dly>30){dly=0;
Serial.print("level ");
Serial.print(lvl);
Serial.print(" inch ");
Serial.println(inches);
if(lvl>99)out=0;
else if(mode==0&lvl<lowset)out=1;

if(m==0) {
//------------------------------
lcd.setCursor(12, 0);
if(lvl<100)lcd.print(" ");
if(lvl<10)lcd.print(" ");
lcd.print(lvl);
lcd.setCursor(5, 1);
if(mode==0)lcd.print("ATO");
else if(mode==1)lcd.print("MAN");

lcd.setCursor(13, 1);
if(out)lcd.print("ON ");
else lcd.print("OFF");
}
else if(sm==1){
if(m==1) {
lcd.setCursor(6, 1);
if(mode==0)lcd.print("ATO");
else if(mode==1)lcd.print("MAN");

}else if(m==2){
lcd.setCursor(7, 1);
lcd.print(lowset);

}

}
}
//----------------------------
digitalWrite(15,out);
//----------------
delay(10);
}
long microsecondsToInches(long microseconds) {
return microseconds / 74 / 2;
}

C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2023912-11772-1jl1fs9.vsaf\sketch_oct12a\sketch_oct12a.ino: In function 'void loop()':
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2023912-11772-1jl1fs9.vsaf\sketch_oct12a\sketch_oct12a.ino:79:12: error: expected ';' before 'if'
'else' if(m==3){
^~~
;
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2023912-11772-1jl1fs9.vsaf\sketch_oct12a\sketch_oct12a.ino:90:5: error: expected '}' before 'else'
else if(m==4){
^~~~
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2023912-11772-1jl1fs9.vsaf\sketch_oct12a\sketch_oct12a.ino:56:29: note: to match this '{'
if( !digitalRead(34)&!st){
^
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2023912-11772-1jl1fs9.vsaf\sketch_oct12a\sketch_oct12a.ino: At global scope:
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2023912-11772-1jl1fs9.vsaf\sketch_oct12a\sketch_oct12a.ino:111:2: error: expected unqualified-id before 'if'
if( !digitalRead(35)&!st){
^~
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2023912-11772-1jl1fs9.vsaf\sketch_oct12a\sketch_oct12a.ino:136:1: error: expected unqualified-id before 'if'
if(dly>30){dly=0;
^~
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2023912-11772-1jl1fs9.vsaf\sketch_oct12a\sketch_oct12a.ino:177:13: error: expected constructor, destructor, or type conversion before '(' token
digitalWrite(15,out);
^
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2023912-11772-1jl1fs9.vsaf\sketch_oct12a\sketch_oct12a.ino:179:11: error: expected constructor, destructor, or type conversion before '(' token
delay(10);
^
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2023912-11772-1jl1fs9.vsaf\sketch_oct12a\sketch_oct12a.ino:180:1: error: expected declaration before '}' token
}
^

Using library Wire at version 2.0.0 in folder: C:\Users\user\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\Wire
Using library LiquidCrystal I2C at version 1.1.2 in folder: C:\Users\user\Downloads\New folder\libraries\LiquidCrystal_I2C
Using library EEPROM at version 2.0.0 in folder: C:\Users\user\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\EEPROM
exit status 1

Compilation error: expected ';' before 'if'

You stubbornly ignore all hints on how to get help. And you are not willing to help us to help you. Didn't you read the advices linked in #3? It is really worth reading them thoroughly!
Take your time. It's worth it, and you'll get help much faster.

1 Like

For which board are you compiling? If it's for an ESP8266, those are not the errors from the code in post #15. That code basically compiles for the Wemos D1 mini.

Which LiquidCrystal_I2C library are you using?

1 Like

new error
Compilation error: 'microsecondsToInches' was not declared in this scope

How must we know what you did to cause that error. So now please learn that every time you make a change and you have problems, you post your code (in a new reply) using code tags. And to make it easier for you, the IDE developers have even added a function to the IDE (edit → copy for forum) to copy the code with code tags so you only have to paste it in a reply.

Deep sigh

i can t understand

arduino ide steps flow this code edit but this erroe
Compilation error: expression cannot be used as a function
hai brother whatsapp contect link & any contect other link