Conveyor State Machine - three run in parallel # denotes number of state machine CurrentState is InitPState Initiates infrastructure for state machine NextState is InitConveyor CurrentState is InitConveyor Display on LED set servo position at beginning if ThisEvent is EF_StartButton Set GameTime as current time set difficulty call servoTimeUpdate CurrentState is DownNormal CurrentState is DownNormal motor down If ThisEvent is EF_Shot# Set NextState to Paused Start EF_TIMER(#, pause time) If ThisEvent is EF_EndGameTime Set NextState to EndGame If ThisEvent is EF_Middle# Set NextState to DownFast If ThisEvent is EF_MonkeyBottom Set NextState to EndGame If ThisEvent is EF_StartButton stop Motor Set NextState to EndGame CurrentState is DownFast motor down fast If ThisEvent is EF_Punch# Set NextState to ClimbingUp start EF_Timer(uptime) If ThisEvent is EF_EndGameTime Set NextState to EndGame If ThisEvent is EF_MonkeyBottom Set NextState to EndGame If ThisEvent is EF_StartButton stop Motor Set NextState to EndGame CurrentState is Paused stop motor If EF_TIMEOUT set next state to DownNormal If ThisEvent is EF_EndGameTime Set NextState to EndGame If ThisEvent is EF_MonkeyBottom Set NextState to EndGame If ThisEvent is EF_StartButton stop Motor Set NextState to EndGame CurrentState is ClimbingUp set motor up If EF_TIMEOUT set NextState to DownNormal If ThisEvent is EF_TopLimit# stop motor Set NextState to DownNormal If ThisEvent is EF_EndGameTime Set NextState to EndGame If ThisEvent is EF_MonkeyBottom stop motor Set NextState to EndGame If ThisEvent is EF_StartButton stop Motor Set NextState to EndGame CurrentState is EndGame Stop motor in SM1: Display win or loss Pause (only in one SM) Reverse motor If ThisEvent is TopLimit# stop motor NextState is ResetGame CurrentState is ResetGame if ThisEvent is EF_ResetComplete NextState is InitConveyor