Question: Lab 5 | Task 1 : Introduction to Timers with LED Blinking 1 . Objective: Demonstrate using Timer 1 to create a precise 1 -

Lab5|
Task 1: Introduction to Timers with LED Blinking
1. Objective: Demonstrate using Timer1 to create a precise 1-second blink interval for an LED without using the delav() function.
2. Instructions:
- Configure Timerl in CTC (Clear Timer on Compare Match) mode.
- Set up an interrupt to toggle an LED every second.
- Verify that the LED blinks with consistent timing by observing the LED behavior.
3. Type in and debug (if necessary:
```
const int ledPin =13; // LED on pin 13
void setup(){
pinMode(ledPin, OUTPUT);
// Configure Timer1 for 1-second intervals
TCCR1A =0; // Normal mode
TCCR1B =(1 WGM12)|(1 CS12)|(1 CS10); // CTC mode,
prescaler 1024
OCR1A =15624; // Compare match for 1 Hz (1 second)
TIMSK1=(1 OCIE1A); // Enable Timer1 compare interrupt
sei(); // Enable global interrupts
}
ISR(TIMER1_COMPA_vect){
digitalWrite(ledPin,!digitalRead(ledPin)); // Toggle LED
}
void loop(){
// No code needed here; LED is controlled by the timer interrupt
}
```
Lab 5 | Task 1 : Introduction to Timers with LED

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!