Timers and interrupts


I would like to make use of a 16-bit timer that is already included in the AVR chip. (TCCRx - Timer/Counter Control Register).

My project is as follows:

I would like to have a timer running in the background independently from the program. The timer needs to be timed out at 2 hours and trigger an interrupt which will activate a servo motor. In the meantime the program just continues as per normal. i thought this would be straightforward but have encountered so many problems that I feel to ask for advice. Do you have a working code snippet showing this routine? The timer doesn't need to be that precise. It could work on the cycles of the 16 MHz chip. Many thanks in advance! Cheers,


Interrupt. Two hours. Mutual exclusion.

A much more reasonable solution is to use blink-without-delay.

The demo several things at a time is an extended example of BWoD

Interrupts are only needed for detecting very short-lived events or for things that happen very frequently.