Pseudo-code for HP Servo ********************************************************************************************** InitializeHPServo // Takes a priority number, returns True. Initialize the MyPriority variable with the passed in parameter. Configure PE0 as analog input Get last state of the analog input pin Set CurrentState to InitAnalogServo Post Event ES_Init to BeamBreak queue (this service) End of InitializeHPServo PostHPServo Takes an input event and posts to service End of PostHPServo CheckHPServo // Takes no parameters, returns True if an event was posted // local RetrunVal = False, CurrentPotState Get the CurrentPotState from the input line If CurrentPotState is within ADC threshold If the CurrentPotState is greater than LastPostState or smaller than LastPotState PostEvent POT_STATE_CHANGED Set LastPotState to CurrentPotState Set ReturnVal = True Endif Endif Return ReturnVal End of CheckHPServo RunHPServo // Takes an event, returns a blank event. // The EventType field of ThisEvent will be one of: TOT_BEAM_BROKEN, POT_STATE_CHANGED, ES_TIMEOUT, HIT_SUCCESS, // HIT_MISTAKE, GAME_OVER. The parameter field of the ThisEvent will be the time that the event occurred. Based on the state of the CurrentState variable choose one of the following blocks of code: CurrentState is InitAnalogServo If ThisEvent is TOT_BEAM_BROKEN Get Current Analog input state Set New Pulse Width corresponding to current input state Set New Pulse Width to HP Servo Pin Set Current Pulse Width to New Pulse Width Set CurrentState to SetAnalogServo Endif End InitAnalogServo block CurrentState is SetAnalogServo If ThisEvent is POT_STATE_CHANGED Set New Pulse Width corresponding to current input state Set New Pulse Width to HP Servo Pin Set Current Pulse Width to Pulse Width Initialize Standby Timer Endif If ThisEvent is ES_TIMEOUT If EventParam is equal to WAIT_TOT_TIMER Set CurrentState to UpdateAnalogServo Endif End SetAnalogServo block CurrentState is UpdateAnalogServo If ThisEvent is HIT_SUCCESS If Current Pulse With - HP Decrement >= PW Minimum Set Current Pulse Width to Current Pulse Width - HP Decrement Set Current Pulse Width to HP Servo Pin Endif Else Set PW Minimum to HP Servo Channel Set EventType to GAME_OVER and EventParam to WIN_VALUE Post Event to TimerServo, HPServo and Gameplay End else Endif If ThisEvent is HIT_MISTAKE If Current Pulse Width + HP Decrement is <= PW Maximum Set Current Pulse Width to Current Pulse Width + HP Decrement Set Current Pulse Width to HP Servo Pin Endif Endif If ThisEvent is GAME_OVER Set CurrentState to FinishAnalogServo Endif End UpdateAnalogServo block CurrentState is FinishAnalogServo If ThisEvent is ES_TIMEOUT Set PW Maximum to HP Servo Pin Set CurrentState to InitAnalogServo Return ES_NO_EVENT End of RunHPServo