
Buttons Driver
Prototype:
uint8_t
ButtonsPoll(uint8_t *pui8Delta,
uint8_t *pui8RawState)
Parameters:
pui8Delta
points to a character that will be written to indicate which button states changed
since the last time this function was called. This value is derived from the debounced state
of the buttons.
pui8RawState
points to a location where the raw button state will be stored.
Description:
This function should be called periodically by the application to poll the pushbuttons. It deter-
mines both the current debounced state of the buttons and also which buttons have changed
state since the last time the function was called.
In order for button debouncing to work properly, this function should be caled at a regular
interval, even if the state of the buttons is not needed that often.
If button debouncing is not required, the the caller can pass a pointer for the
pui8RawState
parameter in order to get the raw state of the buttons. The value returned in
pui8RawState
will
be a bit mask where a 1 indicates the buttons is pressed.
Returns:
Returns the current debounced state of the buttons where a 1 in the button ID’s position indi-
cates that the button is pressed and a 0 indicates that it is released.
3.3
Programming Example
The following example shows how to use the buttons driver to initialize the buttons, debounce and
read the buttons state.
//
// Initialize the buttons.
//
ButtonsInit();
//
// From timed processing loop (for example every 10 ms)
//
...
{
//
// Poll the buttons.
When called periodically this function will
// run the button debouncing algorithm.
//
ucState = ButtonsPoll(&ucDelta, 0);
//
// Test to see if the SELECT button was pressed and do something
//
if(BUTTON_PRESSED(SELECT_BUTTON, ucState, ucDelta))
{
...
// SELECT button action
}
}
18
February 22, 2017