使用中断来处理arduino中的布尔值

时间:2012-12-07 02:08:20

标签: arduino interrupt interrupt-handling

我已经研究了一下,我已经讨论了几个按钮如何用作中断的例子。但是,我试图实现的设计使用模拟传感器。现在,我想做的是让我的模拟传感器标记一个布尔值来告诉中断执行,而不是按钮。我该怎么做?

根据我研究的内容,这是我想到的:

    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
    }

有人可以验证吗?

1 个答案:

答案 0 :(得分:0)

也许我完全错了,但我一直认为Arduino中的中断是基于引脚看到的电压 - 即它们是硬件中断。因此,虽然您的代码对于硬件中断是正确的,但它不适用于变量的更改。

也就是说,此link和此link讨论模拟比较器方法,以完成您要执行的操作。