/*
	funcblk.c

   Sample program showing usage of the timing mechanism provided by 
   function block (costatement) programming.
*/

#use "default.h"
#use vdriver.lib

extern FuncBlk say_goodbye; 

main()
{
int i, j, k;
char on_flag;

	 VdInit();                   // function DelaySec and DelayMs
    i = 0;

    while (1)                   // do an infinite loop
    {
        runwatch();             // monitor with the watch window
        
        funcblk say_hello always_on
        {
            waitfor(DelaySec(5L));          // print every 5 secs
            printf("Hello there %d\n",i++);
            if(i == 5)
                CoBegin(&say_goodbye);      // start other function block
        }

        funcblk say_goodbye
        {
            k = 0;                  // say 5 goodbyes
            while(k<5)
            {
                waitfor(DelaySec(1L));
                printf("Goodbye %d\n", k++);
            }
            i = 0;                  // restart i
        }
    }
}

