64. Interrupt Operation

Question.4

After executing the following code on an Arduino UNO and pressed and released the push button after 50ms, what will happen?

Note: Consider no noise is created from button press.

Code

#define BUTTON_PIN 2  
#define LED_PIN 12

//NOTE: Writing ISR like this is not recommended. It is only for demonstration purposes.
void INT0_ISR() {
  sei();
  while(1);  
}

// ISR: Toggles LED every 1 sec
ISR(TIMER1_COMPA_vect) {
  digitalWrite(LED_PIN, !digitalRead(LED_PIN));
}

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);  // Enable internal pull-up resistor
  pinMode(LED_PIN, OUTPUT);

  // Attach interrupt to pin 2 (INT0) and Trigger on FALLING edge (button press)
  attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), INT0_ISR, FALLING);

  // Configure Timer1 in CTC mode
  TCCR1A = 0;                                         // Normal operation (no PWM)
  TCCR1B = (1 << WGM12) | (1 << CS12) | (1 << CS10);  // CTC Mode, Prescaler = 1024
  OCR1A = 15624;  // Compare match value for 1 second (16MHz / 1024 / 1Hz)
  TIMSK1 |= (1 << OCIE1A);  // Enable Timer1 Compare Match A interrupt

  sei();  // Enable global interrupts
}
void loop() {
}

Select Answer