0值整数不输入If [英] 0 value integer does not enter If
问题描述
我确定这是一个非常基本的编码错误...
I'm sure this is a very basic coding mistake...
我从A0读取数据。如果值为0,我希望将串行的值写入串行监视器。
I'm picking up a reading from A0. If the value is 0, I want the value of the serial to be written to the Serial Monitor.
我还希望它只是第一次写入串行监视器该值降至0.
I also want it only to write to the Serial Monitor for the first time that the value falls to 0.
我不明白为什么,当SensorValue的值= 0时,不执行if。
I don't understand why, when the value for SensorValue = 0, the if is not performed.
这是我的代码:
This is my code:
boolean must_print = true;
int sensorValue = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
sensorValue = analogRead(A0);
if (sensorValue = 0) {
if (must_print = true)
{
must_print = false;
Serial.println(sensorValue);
}
else
must_print = true
}
delay(500); // delay in between reads for stability
}
谢谢!
Thanks!
推荐答案
这不是Arduino论坛但是
This is not an Arduino forum but
您需要使用==,而不是=
you need to use ==, not =
https://en.wikipedia.org/wiki / C_(programming_language)#operators
https://en.wikipedia.org/wiki/C_(programming_language)#Operators
这篇关于0值整数不输入If的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!