Go Down

Topic: RISING and FALLING interrupt on same pin? (Read 1 time) previous topic - next topic


Can I use a single pin to tigger a RISING interrupt service routine, as well as a separate FALLING interrupt service routine?

Jack Christensen

Use a pin change interrupt, or INT0 and INT1 can both be configured to interrupt on any logical change. Looks like it will be up to the code to determine rising or falling, but that should be straightforward. Read the pin first thing in the ISR, if it's low, then falling, if high then rising. So one ISR rather than two, but the same functionality can be accomplished I think.


Thats badically it, the external interrupts int0 and int1 which are on digital pins 2 and 3 can be set to interrupt on rising, falling or change which is the one you want.

For the other interrupts its a little more difficult, but there is a library that helps. here is a quick overview of the library 'pinchaneint'


Duane B


Read this
then watch this


Nick Gammon

Can I use a single pin to tigger a RISING interrupt service routine, as well as a separate FALLING interrupt service routine?

The pin change interrupt isn't going to help any more than doing a CHANGE interrupt would. In any case, there is only one ISR.

Conceivably you could switch from RISING to FALLING inside the ISR, but why bother? By the time you have done that, you may as well have found out (by reading the pin) which one it is.
Please post technical questions on the forum, not by personal message. Thanks!

More info:


Code: [Select]

void setup()
  pinMode(pin, OUTPUT);
  attachInterrupt(0, isr, CHANGE);

void loop()
  digitalWrite(pin, state);

void isr()
  if (digitalRead(2) == HIGH) doRising();  // you can use direct port read to be faster - http://www.arduino.cc/en/Reference/PortManipulation -
  else doFalling();


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131