Function InitButtonEventChecker():
- Initialize LastButtonState to the current state of the button (e.g., PORTBbits.RB2)
- Initialize LastTickCount to the current timer value using ES_Timer_GetTime()
Function Check4Button():
- Initialize ReturnVal to false (default: no event detected)
- Read the current state of the button into CurrentButtonState (e.g., PORTBbits.RB2)
- Declare an Event object ThisEvent
If QueryGameFSM() returns Wait4Input:
- Check if CurrentButtonState is different from LastButtonState:
If CurrentButtonState indicates a button press (e.g., 0):
- Print "Button Down"
- Set ThisEvent.EventType to BUTTON_DOWN
- Post ThisEvent to ButtonModule
- Set ReturnVal to true (indicating an event was detected)
- Update LastButtonState to CurrentButtonState
- Return ReturnVal