Running a background timer


hi all,
i'm wondering how best run timer in background of loop program.  i have simple if/else loop running.  every 5 minutes, however, want toggle relay reset external switch.  is there simple code can include in sketch achieve this?  many thanks!

for longer intervals precision doesn't matter (i'm assuming loop() runs @ least once every 5 minutes) easy thing take note of current time , every pass check if time deed.

code: [select]

loop()
{
  static unsigned long nextswitchtime = millis()+300000;  
 
   if( nextswitchtime < millis() )
   {
       togglerelay();
       nextswitchtime = millis() + 300000;
   }
}


however if need better precision or normal walk through loop takes long time should using interrupts.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Running a background timer


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums