# Need Interrupt to Only Fire Once

**URL:** <https://forum.arduino.cc/t/need-interrupt-to-only-fire-once/638675>\
**Category:** Programming\
**Created:** [February 24, 2020, 11:37pm UTC](https://forum.arduino.cc/t/need-interrupt-to-only-fire-once/638675 "2020-02-24T23:37:08Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![mckennalee24](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mckennalee24](https://forum.arduino.cc/u/mckennalee24)\
**Post date:** [February 25, 2020, 6:25pm UTC](https://forum.arduino.cc/t/need-interrupt-to-only-fire-once/638675/11 "2020-02-25T18:25:51Z")

</div>

Another interesting thing happens if I remove the volatile on the boolean armed. Now it outputs false when the interrupt is NOT triggered and stops outputting with the interrupt is triggered. Almost the exact opposite of what happens in the above code. I really don't understand it. I've been looking into it, but no such luck yet. Any suggestions are welcome 🙂

```cpp
int accelPin = 2; // pin for accelerometer
int laserPin = 12; // pin for laser

// variables that change:
volatile int accelState = LOW;
bool armed = true;

void setup() {
  // initialize the laser pin as an output:
  pinMode(laserPin, OUTPUT);
  // initialize the accelerometer pin as an input:
  pinMode(accelPin, INPUT);
  // attach an interrupt: 
  attachInterrupt(digitalPinToInterrupt(2), pin_ISR, HIGH);
  // initiate serial communication.
  Serial.begin(9600);

}

void loop() {

  Serial.print(armed);
  Serial.print("\n");

}

void pin_ISR () {
  if (armed==true)
    {  
    accelState = digitalRead(accelPin);
    digitalWrite(laserPin, accelState); // output val = input val
    armed = false;
    }
 }

```

---

_[View the full topic](https://forum.arduino.cc/t/need-interrupt-to-only-fire-once/638675)._
