Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何计算Arduino或C环境中的输入状态更改?_Arduino - Fatal编程技术网

如何计算Arduino或C环境中的输入状态更改?

如何计算Arduino或C环境中的输入状态更改?,arduino,Arduino,我正在做一个DIY转速表项目,在这个项目中,我使用一个红外传感器模块来跟踪一个连接到马达的轮子上的黑色条纹。每当传感器位于铝带前面时,传感器模块向Arduino发送低输出,否则发送高输出。我的问题是,每次模块遇到黑色条带时,如何跟踪模块输入中的状态变化 例如,如果发送111111 00000 111111 00000(传感器穿过板条时为“0”序列),则程序应能检测到计数2(即,程序应仅检测下降输入变化,计数器应增加1) 我只想尽可能短的代码摘录,这将做有效的计数。我是个相当业余的程序员,所以我不

我正在做一个DIY转速表项目,在这个项目中,我使用一个红外传感器模块来跟踪一个连接到马达的轮子上的黑色条纹。每当传感器位于铝带前面时,传感器模块向Arduino发送低输出,否则发送高输出。我的问题是,每次模块遇到黑色条带时,如何跟踪模块输入中的状态变化

例如,如果发送111111 00000 111111 00000(传感器穿过板条时为“0”序列),则程序应能检测到计数2(即,程序应仅检测下降输入变化,计数器应增加1)


我只想尽可能短的代码摘录,这将做有效的计数。我是个相当业余的程序员,所以我不知道该怎么做。非常感谢您的帮助。

我认为使用外部中断可以检测输入信号的两个边缘


连接传感器的输出引脚和arduino的INTn。

我认为可以使用外部中断检测输入信号的两个边缘


连接传感器的输出引脚和arduino的INTn。

您只需要准备好您的代码,然后对扫描的“1”设置为true,对“0”设置为false。这应该行得通。如果没有回答这个问题。我会尽力帮助你的

boolean lastscanned = false;
int counter = 0;
void setup() {
    Serial.begin(9600);
}
void loop() {
//do your Read code here:

boolean light;// = paste your result form Reading above here.It has to
// be a boolean (true/false)
if (light = lastscanned) {
//there was no change
}else {
//there was a change
lastscanned = light; //set the lastscanned to the new one.
counter += 1;
Serial.println(counter);
}
}

你只需要你所有准备就绪的代码,然后对扫描的“1”使light boolen为真,对“0”使light boolen为假。这应该行得通。如果没有回答这个问题。我会尽力帮助你的

boolean lastscanned = false;
int counter = 0;
void setup() {
    Serial.begin(9600);
}
void loop() {
//do your Read code here:

boolean light;// = paste your result form Reading above here.It has to
// be a boolean (true/false)
if (light = lastscanned) {
//there was no change
}else {
//there was a change
lastscanned = light; //set the lastscanned to the new one.
counter += 1;
Serial.println(counter);
}
}