Timers in Arduino Duemilanove

Hi, I have the Arduino Duamilanove with Atmega 328. Soon I will need to program a routine like this:

Arduino receive a "1" in a digital input.

  • Start a timer
  • Turn on some indicator leds

The signal at digital input returns to "0" - refresh indicator leds Receive another "1" in the same digital input

  • Reset the timer and start counting again
  • Move a servo
  • refresh indicator leds

This last two steps of the program will be in a infinite loop but if the digital input stays "0" for a specific time (this is the main purpuse of the timer), I will need to move a servo to a "home" position, turn off the leds and try to save power at maximum.

The maxtime until gets in "power saver" will be variable and will need to be set by the user in the first cycle with a pot (probably I will need 1-10 minutes)

BUT the problem is that I never worked with the timers (just delays) but I would like to use the "hardware" timers of the atmega in order to continue refreshing the leds and doing stuff with the micro at the same time the timer still running, ¿where can I read about the use of this timers and probably power saving modes available for this chip? ¿I can achieve time counts as high as 10 minutes?




Nothing you've described requires the use of a dedicated hardware timer.

Check the BlinkWithoutDelay tutorial. The basic idea is to store timestamps, and just check "the time is now X, is there something I need to do?" each time through loop().