*********Pseudo-code for the Rainwater state machine module*********** **** #includes **** pwm library a/d library header file to post event to points service header file to generate random number **** module level variables **** LitColumn (stores 1,2,3) CurrentState MyPriority PotPosition (stores 1,2,3) **** public functions **** InitalizeRainwater() Takes a priority number, returns True. Initialize the MyPriority variable with the passed in parameter. Call Timer Inits for RainTimer Initialize PWM pin of servo and Servo.write to home positon Initialize potentiometer input A/D pin Initialize led pins 1,2,3 (for each column) Set CurrentState to RainwaterPseudoState Pass ES_INIT event to the post function of this service end InitalizeRainwater RunRainwater() Takes an Event and returns an ES_NO_EVENT Initialize local variable NextState Set NextState to CurrentState Case CurrentState: CurrentState is RainwaterPseudoState if ThisEvent is ES_INIT Pulse all LEDs (welcome speed) NextState = Welcome end RainwaterPseudoState CurrentState is Welcome if ThisEvent is GAME_START Turn off all LEDs Start RainTimer to 5 seconds NextState = Waiting end Welcome CurrentState is Waiting if ThisEvent is RAIN_TIMER_TIMEOUT Start RainTimer to 5 seconds Pulse a random (1,2,3) LED Store the LED lit in LitColumn NextState = Raining if ThisEvent is RESET Clear RainTimer Pulse all LEDs (welcome speed) NextState = Welcome end Waiting block CurrentState is Raining if ThisEvent is RAIN_TIMER_TIMEOUT Start RainTimer to 5 seconds if Match()==True Post Points to PointsService Turn off LitColumn LED NextState = Waiting if ThisEvent is RESET Clear RainTimer Pulse all LEDs (welcome speed) NextState = Welcome if ThisEvent is GAME_OVER Pulse all LEDS (fast speed) Clear RainTimer NextState = Celebration end Raining CurrentState is Celebration if ThisEvent is RESET Pulse all LEDs (welcome speed) NextState = Welcome end Celebration end Case Set CurrentState to NextState return ES_NO_EVENT end of RunMaster() ***** event checkers ***** MapServo() Void input, returns false always Initialize local variable PotentiometerInput Read A/D converted value from pot and store in PotentiometerInput Map PotentiometerInput to PotPosition (1,2 or 3 only) Map PotentiometerInput to Servo angle (in terms of PWM argument required) Write that angle value to the Servo return false end MapServo ***** private functions ***** ****************************End Rainwater*****************************