The Button module provides functions to read on-board button/key status. The Button module periodically scans the buttons, in the event loop. When a button is pressed, an integer corresponding to the button is stored in the FIFO. This can be read from the FIFO, and processed at a later time.
The Button module functions are declared in button.h
. The following
example reads the button status and prints it on the LCD.
Listing 10.1. Reading Buttons
#include <board.h>
#include <lcd.h>
#include <button.h>
void main()
{
board_init();
lcd_init();
button_init();
lcd_puts("Press any key\n");
while (1) {
char key;
key = button_getc();
switch (key) {
case 0:
lcd_puts("Key 1 Pressed\n");
break;
case 1:
lcd_puts("Key 2 Pressed\n");
break;
case 2:
lcd_puts("Key 3 Pressed\n");
break;
case 3:
lcd_puts("Key 4 Pressed\n");
break;
}
}
}