Arduino/C ++-如果INT值= X然后 [英] Arduino / C++ - IF INT value = X Then

查看:97
本文介绍了Arduino/C ++-如果INT值= X然后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的arduino代码中有一个INT,我会不断更新它的值,并且我想检查该值并将其与静态值进行比较,并从中运行IF语句.像这样

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() }

上面的示例仅覆盖了原始INT值

the above example just overwrites the original INT value

推荐答案

在C ++中,=是赋值运算符.请使用==进行比较:

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(); }

还要注意小写的if,并且int是不能用作变量名的关键字.

Also note the lowercase if and that int is a keyword which you can't use as variable name.

您可能想查看权威的C ++书籍指南和列表-它为初学者提供了一些有用的资源.

You might want to check out The Definitive C++ Book Guide and List - it has some useful resources for beginners.

这篇关于Arduino/C ++-如果INT值= X然后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆