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!
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.
however if need better precision or normal walk through loop takes long time should using interrupts.
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
Post a Comment