States: OBSTACLE_INIT, OBSTACLE_IDLE, OBSTACLE_PLAYING
Module variables:
currentObstacleTick
adcResults[3]
Init
set MyPriority = given priority
set CurrentState = OBSTACLE_INIT
post ES_INIT to ObstacleService
Post
enqueue ThisEvent to ObstacleService’s queue
Run
switch(CurrentState)
case OBSTACLE_INIT:
if ThisEvent is ES_INIT
set CurrentState = OBSTACLE_IDLE
end if
case OBSTACLE_IDLE:
if ThisEvent is ES_CALIB_DONE
set CurrentState = OBSTACLE_PLAYING
read ADC into adcResults
sample = adcResults[1] // pot on AN1
if sample < 500 // turning CW is faster
tick = OBSTACLE_FAST_TICK
currentObstacleTick = OBSTACLE_FAST_TICK
else
tick = OBSTACLE_SLOW_TICK
currentObstacleTick = OBSTACLE_SLOW_TICK
end if
set PWM on OBSTACLE_SERVO_CH to tick
end if
case OBSTACLE_PLAYING:
if ThisEvent is ES_GAMEOVER_TIMEOUT or ES_NO_INPUT_TIMEOUT
set CurrentState = OBSTACLE_IDLE
currentObstacleTick = OBSTACLE_NEUTRAL_PULSE
set PWM on OBSTACLE_SERVO_CH to OBSTACLE_NEUTRAL_PULSE
end if