Professional Documents
Culture Documents
CheckLEDAlignment, Check4Gun
Data private to module: static uint32_t lastADC[1]
InitDrivingService
RunDrivingService
Define Event ReturnEvent
Set EventType to ES_NO_EVENT
Define NextState
Set NextState to CurrentState
If CurrentState is InitDriving
If ThisEvent is ES_INIT
Configure analog input for potentiometer and IR Transistor
Set up ADC for analog inputs
Configure digital outputs for PointLED pins
Set NextState to Waiting2Begin
If CurrentState is Waiting2Begin
If ThisEvent is ES_BEGIN
Pick PointLED at random
Turn on PointLED
Set Target Timer
Set NextState to Steering
If CurrentState is Steering
Event is ES_ALIGNED
Turn on TargetLED
Set NextState to Aligned
If ThisEvent is ES_TIMEOUT
Turn off PointLED
Pick new PointLED at random
Turn on new PointLED
Reset Target Timer
If ThisEvent is ES_ACTIVITY_TIMEOUT
Turn off PointLED
Disable Target Timer
Set NextState to Waiting2Begin
If ThisEvent is ES_RECEIVE_SERVO_POS
Set CurrentPosition to EventParam
If CurrentState is Aligned
If ThisEvent is ES_TARGET_SHOT
Turn off PointLED
Pick new PointLED at random
Turn on new PointLED
Turn off TargetLED
Reset Target Timer
Reset Activity Timer
Create ES_ADD_SCORE event
Set EventParam to 5 (points to be added to score)
Post event to LEDService
Set NextState to Steering
If ThisEvent is ES_TIMEOUT
Turn off PointLED
Pick new PointLED at random
Turn on new PointLED
Turn off TargetLED
Reset Target Timer
Set NextState to Steering
If ThisEvent is ES_ACTIVITY_TIMEOUT
Turn off TargetLED
Turn off PointLED
Disable Target Timer
Set NextState to Waiting2Begin
If ThisEvent is ES_NOT_ALIGNED
Turn off TargetLED
Set CurrentState to Steering
If ThisEvent is ES_RECEIVE_SERVO_POS
Set CurrentPosition to EventParam
Set CurrentState to NextState
Return ReturnEvent
CheckLEDAlignment
Check4Gun