Pseudo-code for Dodge Button module ************************************************************************************** InitializeButtonDebounce //Takes a priority number, returns True. Initialize the MyPriority variable with the passed in parameter. Initialize the port line to monitor the buttons - using PD0 for left button, PD1 for right button Sample the button port pins and use them to initialize LastButtonState_L and LastButtonState_R Set CurrentState to be DEBOUNCING Start debounce timer (timer posts to ButtonDebounceSM) End of InitializeButtonDebounce PostButtonService Takes an event and posts to service End of PostBeamBreak CheckButtonEvents //Takes no parameters, returns True if an event was posted local RetrunVal = False, CurrentButtonState Set CurrentButtonState_L to state read from port pin PD0 Set CurrentButtonState_R to state read from port pin PD1 If the state of the port line PD0 has changed If the current state of the port line is LO PostEvent BUTTON_PRESSED with parameter 'L' Set ReturnVal = True Endif If the state of the port line PD1 has changed If the current state of the port line is LO PostEvent BUTTON_PRESSED with parameter 'R' Set ReturnVal = True Endif Set LastButtonState_L to CurrentButtonState_L Set LastButtonState_R to CurrentButtonState_R Return ReturnVal End of CheckButtonEvents RunButtonDebounce //Takes an input event, returns a blank event //The EventType field of the input Event will be one of: ButtonPressed, or ES_TIMEOUT. Based on the state of the CurrentState variable choose one of the following blocks of code: CurrentState is Debouncing If ThisEvent is ES_TIMEOUT and Set CurrentState to Ready2Sample Endif End Debouncing block CurrentState is Ready2Sample If ThisEvent is BUTTON_PRESSED Initialize BUTTON_TIMER with Debounce Time Set CurrentState to Debouncing Post Event to PostDodgeRegister Endif End Ready2Sample block Set CurrentState to NextState Return ES_NO_EVENT End of RunButtonDebounce