Module level variables: LastInputState, CurrentState FUNCTION InitializeBasket - Initializes state machine. (Follows format for Events and services framework) Initialize the port line to receive beam break signals Initialize the port line to send basket light signals Sample port line and use it to initialize the LastInputState variable Set CurrentState to be InitBasket Post Event ES_Init to MorseElements queue (this service) END InitializeBasket FUNCTION RunBasket Create return variable and set it to ES_NO_EVENT If the current state is InitBasket and Event type is ES_INIT Next state to WelcomeLights off Set timer for basket lights End If If the current state is WelcomeLightsOn If the master SM sends a GAME_START event, switch to PlayingLightsOn Stop timer Change to playing state End If If we have a timeout Event Turn Lights on Reset Timer Switch to WelcomeLightsOn End If End If If the current state is WelcomeLightsOn If the master SM sends a GAME_START event Stop timer Change to playing state off Turn lights off End If If this is a timeout event Turn Lights off Reset Timer Switch to WelcomeLightsOff End If End If If the current state is PlayingLightsOff If a BASKET_MADE event is detected Reset inactivity timer Send a point to point SM Set Counter variable Set Timer Preserve current state End If If this is a timeout event If the counter is equal to zero We stop flashing Otherwise if counter is greater than zero Decrement the counter Set the timer again Turn the Lights on Change state variable End If If the master SM sends a RESET event Change back to welcome mode Set timer for welcome mode flashing End If If the master SM sends a GAME_OVER event, switch to celebration mode Change to Celebration mode Set timer for celebration flashing End If End If If the current state is PlayingLightsOn If a BASKET_MADE event is detected Reset inactivity timer Send a point to point SM Set Counter variable Set Timer Preserve current state End If this is a timeout event If the counter is equal to zero Turn lights off Change state to PlayingLightsOff Otherwise if counter is greater than zero Decrement the counter Set the timer again Turn the Lights off Change state variable End If If the master SM sends a RESET event Turn lights off Change back to welcome mode Set timer for welcome mode flashing End If If the master SM sends a GAME_OVER event Turn Lights off Change to Celebration mode Set timer for celebration flashing End If End If If the current state is CelebrationLightsOff If this is a RESET event Change back to welcome mode Set timer for welcome mode flashing End If If this is a timeout event Turn lights on Set timer for celebration mode flashing Set next state End If End If If the current state is CelebrationLightsOff If this is a RESET event Turn lights off Change back to welcome mode Set timer for welcome mode flashing End If If this is a timeout event Turn lights off Set timer for celebration mode flashing Set next state End If End If Update current state Return return variable END RunBasket FUNCTION CheckBasket local varables: CurrentInputState, ReturnVal Set ReturnVal to false Set CurrentInputState from the input line If CurrentInputState is not equal to LastInputState If the current state of the input line is high A basket had been made. Post event to BasketSM End If Set ReturnVal to true End If Update LastInputState to CurrentInputState Return ReturnVal; END CheckBasket