我已经研究了一下,我已经讨论了几个按钮如何用作中断的例子。但是,我试图实现的设计使用模拟传感器。现在,我想做的是让我的模拟传感器标记一个布尔值来告诉中断执行,而不是按钮。我该怎么做?
根据我研究的内容,这是我想到的:
boolean isWall;
attachInterrupt(isWall, interruptFunction, RISING);
void loop() {
if(analogSensor.response > 450) {
isWall = true;
}
normalExecution(); // what it normally does if isWall is false
}
void interruptFunction() {
// code implementation
isWall = false; // set isWall back to false after executing interruptFunction
}
void normalExecution() {
// foo
}
有人可以验证吗?