Arduino / C++ - IF INT value = X Then

别说谁变了你拦得住时间么 提交于 2020-08-10 18:53:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!