/*
	READKEY.C

   PK21xx/Rugged Giant and PK22xx/Little Star Sample Program that illustrates
	reading the 12 keys of the keypad.
	
   "i" is incremented and periodically displayed on the LCD and the STDIO
   window.

   Type i on the watch window to monitor the value of i.
*/

#use "default.h"
#use cplc.lib

#if !(BOARD_TYPE==CPLC_BOARD || BOARD_TYPE==L_STAR)
#fatal "This program only runs on a PK21xx/Rugged Giant or a PK22xx/Little Star"
#endif

#define NOUNIVERSAL 1        // disable the virtual drivers for the io's

main()
{
    int          k;
    unsigned int i;
    
    uplc_init();
    lcd_printf(0L, "hello World");

    while (1)                // loop forever
    {
        while (i++ < 50000 && ((k = lc_kxget(0)) < 0)) 
            runwatch();
                             // wait for a key or end of count
        if (i >= 50000)
        {
            i = 0;
            lcd_erase_line(1);
            lcd_printf(0x01000000, "finished counting");
            printf("finish counting\n");
        }
        else
        {
            up_beep(100);    // beep for 100 ms
            lcd_erase_line(1);
            lcd_printf(0x01000000, "key %3d pressed", k);
            printf("%d\n", k);
        }
    }
}
