Question.6
An external signal of 5 kHz is applied to digital pin 5 (Timer 1) of Arduino UNO. What will be the status of LED? (after executing the following code)
Code:
const int ledPin = 8;
void setup() {
pinMode(ledPin, OUTPUT);
// Configure Timer1 for normal mode
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
// External clock source on T1 (rising edge, no prescaler)
TCCR1B |= (1 << CS12) | (1 << CS11) | (1 << CS10);
// Clear overflow flag initially
TIFR1 |= (1 << TOV1);
}
void loop() {
// Wait here until the overflow flag is set
while (!(TIFR1 & (1 << TOV1)));
TIFR1 |= (1 << TOV1); // Clear the flag
digitalWrite(ledPin, !digitalRead(ledPin)); // Toggle LED
}