65. Interrupt Conditions

Question.1

Analyze the code and circuit, what will be the output on the serial monitor after we press and release the button after 50 ms?

Note: Consider no noise is created from button press.

Code

#include <avr/interrupt.h>

volatile int interruptCount = 0;

void setup() {
  Serial.begin(115200);
  pinMode(8, INPUT_PULLUP);

  // Enable Pin Change Interrupt Control Register for PCIE0 (which covers pins PCINT0 to PCINT7)
  PCICR |= (1 << PCIE0);

  // Enable pin change interrupt for PCINT0 (corresponding to digital pin 8 on Arduino UNO)
  PCMSK0 |= (1 << PCINT0);

  sei();
}

void loop() {
  // Main loop does nothing, all handled by interrupts
}

ISR(PCINT0_vect) {
  interruptCount++;
  Serial.print("Interrupt Triggered: ");
  Serial.println(interruptCount);
}

Select Answer