RISING and FALLING ISR on same pin?

Can I attach two interrupt service routines to the same pin -- one for the RISING edge and one for the FALLING edge? Such as:

attachInterrupt (3, upISR, RISING);
attachInterrupt (3, downISR, FALLING);

...

Can I attach two interrupt service routines to the same pin

No.

No, but using change interrupt you can then read the actual pin value while in the ISR and perform two different things depending on the pin value.

Lefty

retrolefty:
No, but using change interrupt you can then read the actual pin value while in the ISR and perform two different things depending on the pin value.

Lefty

Oh yeah, thanks. Of course...!

Maybe a dumb-looking question, but what will be the digitalRead of the FALLING pin (and RISING vice versa)?

Has it already became zero, when I read it at the beginning of the ISR (activated on FALLING edge)? :wink:

I've read around the place that people reckon a pin is considered high when the voltage is above/at ~3.3v, so I would imagine, to detect a falling edge, the voltage must drop below this threshold rendering the pin as a low state before the ISR is triggered.

I'm probably wrong though. :slight_smile:

Logic tells me you are right. The ISR digitalRead should be zero when the pin is FALLING :).

But here
http://www.rotwang.co.uk/projects/docs/triac_control.ino
I see completely opposite result

ISR code:

void on_change()
{
const int p = digitalRead(optoPin);

if (p)
{
// end of cycle
set_state(ZERO);
} else {
// start of cycle.
set_state(PHASE);
}
}

As you can see, the programmer expects the "if (p)", which is the discussed pin digitalRead, to be positive at the end of AC cycle (= at the FALLING edge).

But he may be wrong :slight_smile: The time difference in his application between the RISING and FALLING edge is minimal, so the program will probably work even with the swapped cases.

The ISR digitalRead should be zero when the pin is FALLING

If the Arduino reference page is to be believed (not always the case) I agree with you. To quote from the reference page for attachInterrupt() in the section describing interrupt modes.

FALLING for when the pin goes from high to low.

digitalRead should be zero when the pin is FALLING

Yes it is.
And one when rising.

simple example of reading a pulse using CHANGE and digitalRead for the pin state

Duane B

rcarduino.blogspot.com