A breathing LED with a timer interrupt
Video lesson · in the full course
We keep the PWM from lesson 4.2 and add TIM1 as a 1 kHz interrupt. Every millisecond its callback raises the duty cycle by one. The main loop is empty, and the LED fades in exactly once per second.
What this lesson covers
- TIM1: 1 kHz update
- Turn on the TIM1 update interrupt
- Start TIM1 with interrupts
- The period-elapsed callback
- Slow it down with the repetition counter
By the end, your LED fades up once a second, over and over, while main() does nothing at all.
The full course has the video, every step with screenshots, the code with a copy button, and the checks and fixes. $20 once unlocks this lesson, the other 7 full-course lessons and 36 bonus lessons, and you can ask me questions under each one. Checkout on steppeschool.com; 14-day money-back guarantee.