beautypg.com

Non-blocking delay timers – Wavetronix Click 500 (programmable controller) (CLK-500) - Developer Guide User Manual

Page 62

background image

CHAPTER 6 • TIMERS AND CLOCKS 61

void Mode2( void )
{
if (Startup == TRUE)
{
// Blocking wait
ClickLedOn(ALLRED);
ClickUtilPause(10000);
ClickUtilUserWatchDogHit();
ClickLedOff(ALLRED);
ClickUtilConditionalPause(10000,ClickBtnPressed);
Startup = FALSE;
ClickLedOff(ALLRED);
}
else
{
PlayPauseBtnCheck();
}
UpdateProgress();
}

Non-blocking Delay Timers

Another way to create delays is to set up a ClickUtilTimer object. When the timer expires,

a conditional statement in the current operating mode can be executed. For example, Mode

1 in the example below creates a startup delay like the preceding example in Mode 2. How-

ever, the yellow LED progress indication bar will be running during the wait time. The Clic-

kUtilTimerSet and ClickUtilTimerExpired utility functions are used by a ClickUtilTimer

object named WaitTimer to accomplish this type of cooperative multitasking.

void Mode1( void )
{
if (Startup == TRUE)
{
// Non-blocking wait
if (WaitTimer.active == FALSE)
{
ClickLedOn(ALLRED);
ClickUtilTimerSet(&WaitTimer, 10000);
}
if (ClickUtilTimerExpired(&WaitTimer))