Vous êtes sur la page 1sur 10

Event Checkers: Start Button Hit Left Holster Removed Left Holster Replaced Right Holster Removed Right

Right Holster Replaced Left Shake Detected Right Shake Detected Left Score Lower Limit Hit Left Score Upper Limit Hit Right Score Lower Limit Hit Right Score Upper Limit Hit Action Functions: Motors LEDs Fan Difficulty

Pseudo-Code
Event Checkers
Start Button Hit ReturnVal = FALSE IF Debounce Time is less than threshold IF CurrentState is down and is not equal to LastState Post Event StartSelected ReturnVal = TRUE End IF Set TimeOfLastSample equal to the current time End IF Set LastInput equal to CurrentInput Return ReturnVal Left Holster Removed and Replaced ReturnVal = FALSE IF Debounce Time is less than threshold IF CurrentState is not equal to LastState IF CurrentState is up Post Event LeftHolsterRemoved Else CurrentState is down PostEvent LeftHolsterReplaced End IF ReturnVal = TRUE End IF Set TimeOfLastSample equal to the current time End IF Set LastInput equal to CurrentInput Return ReturnVal

Right Holster Removed and Replaced ReturnVal = FALSE IF Debounce Time is less than threshold IF CurrentState is not equal to LastState IF CurrentState is up Post Event RightHolsterRemoved Else CurrentState is down PostEvent RightHolsterReplaced End IF ReturnVal = TRUE End IF Set TimeOfLastSample equal to the current time End IF Set LastInput equal to CurrentInput Return ReturnVal Left Shake Detected ReturnVal = FALSE Set AccelInput to current value from accelerometer IF AccelInput is greater than upper threshold Set CurrentInput high Else IF AccelInput is less than lower threshold Set CurrentInput low End IF IF Debounce Time is less than threshold IF CurrentState is high and is not equal to LastState Post Event LeftShakeDetected ReturnVal = TRUE End IF Set TimeOfLastSample equal to the current time End IF Set LastInput equal to CurrentInput Return ReturnVal

Right Shake Detected ReturnVal = FALSE Set AccelInput to current value from accelerometer IF AccelInput is greater than upper threshold Set CurrentInput high Else IF AccelInput is less than lower threshold Set CurrentInput low End IF IF Debounce Time is less than threshold IF CurrentState is high and is not equal to LastState Post Event RightShakeDetected ReturnVal = TRUE End IF Set TimeOfLastSample equal to the current time End IF Set LastInput equal to CurrentInput Return ReturnVal Left Score Lower Limit Hit ReturnVal = FALSE IF Debounce Time is less than threshold IF CurrentState is down and is not equal to LastState Post Event LeftLowerLimitHit ReturnVal = TRUE End IF Set TimeOfLastSample equal to the current time End IF Set LastInput equal to CurrentInput Return ReturnVal Left Score Upper Limit Hit ReturnVal = FALSE IF Debounce Time is less than threshold IF CurrentState is down and is not equal to LastState Post Event LeftUpperLimitHit ReturnVal = TRUE End IF Set TimeOfLastSample equal to the current time End IF Set LastInput equal to CurrentInput Return ReturnVal

Right Score Lower Limit Hit ReturnVal = FALSE IF Debounce Time is less than threshold IF CurrentState is down and is not equal to LastState Post Event RightLowerLimitHit ReturnVal = TRUE End IF Set TimeOfLastSample equal to the current time End IF Set LastInput equal to CurrentInput Return ReturnVal Right Score Upper Limit Hit ReturnVal = FALSE IF Debounce Time is less than threshold IF CurrentState is down and is not equal to LastState Post Event RightUpperLimitHit ReturnVal = TRUE End IF Set TimeOfLastSample equal to the current time End IF Set LastInput equal to CurrentInput Return ReturnVal

Main State Machine


Set NextState to CurrentState Based on the state of CurrentState choose one of the following: CurrentState is InitMain Set NextState to BothIn Turn on BothInLEDs End InitMain CurrentState is BothIn IF ThisEvent is LeftRemoved Set NextState to LeftOut Turn on LeftOut LEDs End IF IF ThisEvent is RightRemoved Set NextState to RightOut Turn on RightOut LEDs End IF IF ThisEvent is StartSelected Set NextState to BothIn Flash BothIn LEDs End IF End BothIn CurrentState is LeftOut IF ThisEvent is LeftReplaced Set NextState to BothIn Turn on BothIn LEDs End IF IF ThisEvent is RightRemoved Set NextState to BothOut Turn on BothOut LEDs End IF IF ThisEvent is StartSelected Set NextState to LeftOut Flash LeftOut LEDs End IF End LeftOut

CurrentState is RightOut IF ThisEvent is LeftRemoved Set NextState to BothOut Turn on BothOut LEDs End IF IF ThisEvent is RightReplaced Set NextState to BothIn Turn on BothIn LEDs End IF IF ThisEvent is StartSelected Set NextState to RightOut Flash RightOut LEDs End IF End RightOut CurrentState is BothOut IF ThisEvent is LeftReplaced Set NextState to RightOut Turn on RightOut LEDs End IF IF ThisEvent is RightReplaced Set NextState to LeftOut Turn on LeftOut LEDs End IF IF ThisEvent is StartSelected Set NextState to GameStarted Turn Off All LEDs Flash Red LED Flash Yellow LED Flash Green LED Read In Difficulty Set Timer End IF End BothOut

CurrentState is GameStarted Set TimerCounter = 0; IF ThisEvent is EF_Timeout IF TimerCounter is less than 10 Set NextState to GameStarted Flash Green LED Set Timer Else IF TimerCounter is less than 20 Set NextState to GameStarted Flash Yellow LED Set Timer Else IF TimerCounter is less than 30 Set NextState to GameStarted Flash Red LED Set Timer Else IF TimerCounter is equal to 30 Set NextState to GameOver Turn Off Fan Turn Off All LEDs Set Timer IF RightScore is greater or equal to LeftScore IF Right Score is greater than ScoreThreshold Turn on RightMediumOutcome LEDs Else Turn on RightBadOutcome LEDs End IF Else IF Left Score is greater than ScoreThreshold Turn on LeftMediumOutcome LEDs Else Turn on RightMediumOutcome LEDs End IF End IF End IF End IF IF ThisEvent is LeftShakeDetected Set NextState to GameStarted Pulse left score motor Increment left score Turn on Fan End IF

IF ThisEvent is RightShakeDetected Set NextState to GameStarted Pulse right score motor Increment right score Turn on Fan End IF IF ThisEvent is LeftUpperLimitHit Set NextState to BothOut Turn on BothOut LEDs End IF IF ThisEvent is RightUpperLimitHit Set NextState to LeftOut Flash LeftOut LEDs End IF End GameStarted CurrentState is GameOver IF ThisEvent is EF_Timeout Set NextState to Resetting Turn off all LEDs Reset Left and Right Score Motors End IF End GameOver CurrentState is Resetting IF ThisEvent is LeftLowerLimitHit Set NextState to LeftReset Stop Left Score Motor End IF IF ThisEvent is RightLowerLimitHit Set NextState to RightReset Stop Right Score Motor End IF End Resetting CurrentState is LeftReset IF ThisEvent is RightLowerLimitHit Set NextState to BothReset Stop Right Score Motor End IF End LeftReset

CurrentState is RightReset IF ThisEvent is LeftLowerLimitHit Set NextState to BothReset Stop Left Score Motor End IF End RightReset CurrentState is BothReset Reset Left and Right Scores Check HolsterStatus IF HolsterStatus equals BothOut Set NextState to BothOut Turn on BothOut LEDs Else IF HolsterStatus equals Left Out Set NextState to LeftOut Turn On LeftOut LEDs Else IF HolsterStatus equals RightOut Set NextState to RightOut Turn On RightOut LEDs Else Set NextState to BothIn Turn On BothIn LEDs End IF End BothReset End Main SM

Vous aimerez peut-être aussi