Arduino 中的逻辑非运算\n
使用 ! 运算符执行逻辑非运算。真值表如下 −
| 表达式 | 输出 |
|---|---|
| T | F |
| F | T |
如你所见,逻辑非运算会反转表达式的真值。
示例
可以从下面给出的示例中理解用法 −
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println();
int i = 10;
if (!(i > 10)) {
Serial.println("i is NOT greater than 10");
}
else {
Serial.println("i is greater than 10");
}
}
void loop() {
// put your main code here, to run repeatedly:
}输出
串行监视器输出如下所示 −

在等待某些事情变为真时通常使用 NOT 函数。
while(!condition){
//do something
}例如,如果你在等待串行输入,
while(!Serial.available()){
//Wait
}当 Serial.available() 返回大于 0 的值(即接收到串行输入时),上面的循环将中断。
广告
数据结构
组网
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP