Servo Timer Service
Servo Timer Service
/*
This module handles controlling the Servo motor, which acts as a timer showing time
elapsed in the game. Sends LOSE events back to GameProgressionService to show when
players have run out of time. Also accepts END_GAME events from
GameProgressionService when the game ends for another reason and the servo should
be reset to starting position.
*/
InitServoTimer
set current state to initial pseudostate
set TimeElapsed to 0
set up PWM
set starting servo position to FULL_CCW
RunServoTimer
switch on current state:
initial pseudostate:
if received ES_INIT event:
set current state to ServoTimerIdle
ServoTimerIdle:
if received START_GAME event:
set current state to CountingDown
initialize SERVO_TIMER
CountingDown:
switch on Event Type:
// every time the timer times out, the servo motor will
move to show the progression of time
ES_TIMEOUT:
// move servo to new time position
set pulse width for PWM to FULL_CCW -
STEP_SIZE*TimeElapsed