Reputation: 812
i'm trying to write a boolean calculator in arduino. But I get this error and I can't figure out what's wrong: unqualified-id before '!' token
It highlights the 4th line. Here's my code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
byte verticalLine[8] = { // Custom character (vertical line), 5 X 7. 1 = pixel on, 0 = pixel off.
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000
};
boolean not(boolean X)
{
return !X;
}
boolean and(boolean A, boolean B)
{
if(A && B) return true;
else return false;
}
boolean or(boolean A, boolean B)
{
if(A || B) return true;
else return false;
}
boolean xor(boolean A, boolean B)
{
return or(and(not(A), B), and(A, not(B));
}
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
lcd.print("Hello World!");
lcd.createChar(0, verticalLine);
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0, 1); //first character of second row.
lcd.write(0); // writes my custom character.
}
The only !
I see is in the not() method, is it a problem?
EDIT: I tried changing the not() method to:
if(X) return false;
else return true;
so there are no !
in my code, but it still gives that error.
I even tried removing the semicolon in the 3rd line, but it still gives that error and highlights the 4th line, which is really weird...
Thanks.
Upvotes: 0
Views: 106
Reputation: 4840
not
is a reserved word in C++ so you can't use it as a function name. Reference.
In C these are also defined by the language but instead of being keywords they are defined in the file iso646.h
e.g.
#define not !
You should also have problems with and
or
xor
.
Upvotes: 1