LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

5 second timer

hi,
i dont´t know how to build a timer that delivers a boolean "true" every 5 seconds for running a case-structure.
can anyone give me an advise?

thx
0 Kudos
Message 1 of 2
(3,104 Views)
Hello Reen -

Do you want a function you can poll and have it return TRUE if 5 seconds have gone by?
Note that C does not have a native BOOL type, but integers can be used in logical expressions, with 0 being false and non-zero being true.
I think this code should work --- let me know if it doesn't. Bob

#include
#define TRUE 1
#define FALSE 0

static unsigned short CheckFiveSecondsElapsed(void) {

static time_t oldtime;
time_t newtime = time(&newtime);

if (difftime(newtime, oldtime) >= 5) {
oldtime = newtime;
return TRUE;
}
else {
return FALSE;
}

} // end, CheckFiveSecondsElapsed
0 Kudos
Message 2 of 2
(3,069 Views)