0

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

RayShifter
  • 15
  • 6

1 Answers1

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.

Martin Konrad
  • 1,075
  • 1
  • 10
  • 20