65. Interrupt Conditions

Question.4

After uploading below code to an Arduino UNO, a 100-cycle square wave (62.5 ns high, 62.5 ns low) is applied to INT0 (Digital Pin 2)

After that, when a push button connected to Pin 8 is pressed and released once what value prints on the Serial Monitor?

Note: Consider that no noise is created from button press.

Code

#define INTERRUPT_PIN 2
#define SWITCH_PIN 8

int counter = 0;

void ISR_INT0() {
  counter++;
}

void setup() {
  Serial.begin(115200);
  pinMode(INTERRUPT_PIN, INPUT_PULLUP);
  pinMode(SWITCH_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), ISR_INT0, FALLING);
}

void loop() {
  if (!digitalRead(SWITCH_PIN)) {
    Serial.println(counter);
    while (!digitalRead(SWITCH_PIN));
    counter = 0;
  }
}

Select Answer