0% found this document useful (0 votes)
24 views1 page

Servo Timer Service

This module handles controlling a servo motor timer that shows elapsed time in a game and sends loss events when time runs out. It accepts initialization and end game events, sets the servo position based on time, and resets the timer on game over.

Uploaded by

tabitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

Servo Timer Service

This module handles controlling a servo motor timer that shows elapsed time in a game and sends loss events when time runs out. It accepts initialization and end game events, sets the servo position based on time, and resets the timer on game over.

Uploaded by

tabitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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

post initial transition event

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

if MAX_TIME has elapsed:


set current state to Timeout
set TimeElapsed back to 0
send LOSE event to GameProgressionService
else:
increment TimeElapsed
initialize SERVO_TIMER
END_GAME:
// reset timer back to 0
set pulse width form PWM to FULL_CCW
set TimeElapsed to 0
set CurrentState to ServoTimerIdle
Timeout:
if received END_GAME event:
// reset timer back to 0
set pulse width form PWM to FULL_CCW
set TimeElapsed to 0
set CurrentState to ServoTimerIdle

You might also like