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

查看:25
本文介绍了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(); }

还要注意小写的 ifint 是一个不能用作变量名的关键字.

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

您可能想查看 The Definitive C++ Book Guide and List - 它为初学者提供了一些有用的资源.

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天全站免登陆