Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Interrupt on Rising and Falling on the same pin

  1. #1

    Interrupt on Rising and Falling on the same pin

    I've got a pulse coming in on pin 0 and trying to measure the pulse width.

    I'm using ISR on the falling and rising edge of the same pin but it looks like the ISR is only calling on the rising edge.

    Can I use attachInterrupt() twice on the same pin on both FALLING and RISING ?

    int led = 13;
    int rx_pin = 0;
    void setup() 
      pinMode(led, OUTPUT);    
      pinMode(rx_pin, INPUT); 
    void loop() 
    void fallingISR()
      digitalWrite(led, HIGH);  
    void risingISR()
      digitalWrite(led, LOW);  

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Colmar, France
    No, you can't since only one single interrupt vector can be assigned at a time. But you could use "BOTH" and check for the pin voltage (i.e. with digitalReadFast()) within your interrupt handler to check if it was rising or falling.

    Another strategy could be to change the interrupt attachment within the interrupt handlers themselves. For example attach RISING in setup to have a defined starting point, attach FALLING within risingISR() and RISING within fallingISR().

  3. #3
    I've changed it to "CHANGE" and test the voltage inside the ISR. It worked !!

    Thank you for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts