title: Multiple Arduino Interrupts on same pin
body: <p>In the following code, why does <code>ISR2</code> never run? </p>
  
  <pre><code>const int in = 19;
  const int LED = 9;
  int flag;
  void setup() {
      pinMode(in, INPUT_PULLUP);
      pinMode(LED, OUTPUT);
      attachInterrupt(digitalPinToInterrupt(in), ISR2, RISING);
      attachInterrupt(digitalPinToInterrupt(in), ISR1, FALLING);
  
  }
  void  loop() {
      if (flag) {delay (100); flag = false;}// debounce
  }
  void ISR1(){
      digitalWrite(LED, LOW);
      // Turn Off the motor, since, Limit Switch was engaged
      flag = true;
  }
  void ISR2(){ // Limit Switch was disengaged. 
      digitalWrite(LED, HIGH);
      delay(100); // Debounce, so I do not receive spurious FALLING edges from this.
  }
  </code></pre>
  
  <p>Does the Arduino not allow you to attach two interrupts on the same pin even if the interrupts are programmed for different events?</p>
  
  <p>In my setup, pin 19 gets a signal from a limit switch used in a motion control setup. When the limit switch is engaged, the <code>in</code> pin gets <code>LOW</code> signal. Thus, I first see a <code>FALLING</code> edge followed by <code>RISING</code> edges and <code>FALLING</code> edges due to mechanical bounce. I handle the debouncing correctly in this case. </p>
  
  <p>However, imagine the Limit Switch was sitting in engaged state for a while, and then I reverse the motor causing the Limit Switch to disengage, this will send a <code>RISING</code> edge followed by <code>FALLING</code> and <code>RISING</code> edges. I need to ignore these edges since nothing is in danger. The <code>ISR2</code> was written with purpose of capturing the first <code>RISING</code> edge when the Limit switch disengages, and then debouncing it so that the following <code>FALLING</code> edges are ignored. But now that <code>ISR2</code> never gets called, how can I deal with this situation?</p>
  
  <p>P.S. My microcontroller is ATMEGA 2650, It's a Arduino Mega board.</p>