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