Pages: [1]   Go Down
Author Topic: Internal Interrupts?  (Read 373 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've researched a bit, and I've ran into a couple of examples of how buttons are used as interrupts. However, the design I'm trying to implement uses analog sensors. Right now, what I want to do is to have my analog sensors flag a boolean to tell the interrupt to execute, not a button. How would I do so?

This is what I have thought up based on what I researched:

    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
    }
Can someone verify?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I've ran into a couple of examples of how buttons are used as interrupts.
Only in a most awkward and unnecessary manner. Interrupts are cause by external events, like serial data arriving, or by things that happen very frequently, and need to not be missed, like encoders rotating.

If a switch is connected, it should be polled in loop().

Analog devices do not trigger interrupts, because the time taken to read an analog sensor is so long, in terms of how many times loop() could loop, that polling is fast enough.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18807
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Let's get back to the real world. What is your application? Why do you need to know if an analog input changes? Is this something to do with watering plants? If so you hardly need to turn the sprinklers on with microsecond precision.
Logged


Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How would I do so?

Three ways:

1) continuous adc: have a free running adc and once the result is over a threshold, raise a flag. This can be a MIPS drain;
2) use a comparator: use the analog comparator to trigger an event.
3) use the digital input's threshold hold: apply the input to a digital pin and it will trigger a logic '1' when the Vhi(th) minimum is reached.

Logged

Pages: [1]   Go Up
Jump to: