问题
i have an INT in my arduino code that i constantly update it's value and i want to check the value and compare it to static values and run IF statments out of it. Something like this
INT = 3
If (int = 1) { run1() }
If (int = 2) { run2() }
If (int = 3) { run3() }
the above example just overwrites the original INT value
回答1:
In C++ =
is the assignment operator. Please use ==
to compare:
int i = 3;
if (i == 1) { run1(); }
if (i == 2) { run2(); }
if (i == 3) { run3(); }
Also note the lowercase if
and that int
is a keyword which you can't use as variable name.
You might want to check out The Definitive C++ Book Guide and List - it has some useful resources for beginners.
来源:https://stackoverflow.com/questions/62983799/arduino-c-if-int-value-x-then