In the previous post we learned how to blink an LED with an ATtiny85 by using a _delay_ms() function to halt the program execution after turning on and off the LED. The downside to this approach is that the _delay_ms() causes our code to hang up while the function spins in a loop up to the specified time. This is a waste of CPU clock cycles, and makes doing anything else in the event loop nearly impossible. Let’s stop the pointless spinning.
In this post I will introduce the two timer/counter hardware peripherals that are inside the ATtiny85 chip, and show how we can offload the job of blinking an LED to one of them with the added benefit of using no clock cycles on the task. This frees the CPU up to do whatever else we wish while our LED reliably blinks away. If you are coming from a typical Arduino upbringing, this sort of flexibility and power is what makes learning how to truly program a microcontroller and its peripherals worth the effort.