Documente Academic
Documente Profesional
Documente Cultură
CurrentState is SharkOFF
If ThisEvent is FireButtonDown
Set NextState to CurrentState
Endif
If ThisEvent is LaserOnDetector
Set CurrentTarget to ThisEvent.EventParam (EventParam is the target #)
Call ShiftRegister_TargetAcquiredLED(true)
Set NextState to SharkON
Endif
If ThisEvent is MainTimeout or Abort
FULL_RESET
EndIf
End SharkOFF block
CurrentState is SharkON
If ThisEvent is FireButtonDown
If BombsLeft is 1
Set NextState to Joy
Call ShiftRegister_TargetAcquiredLED(false)
Call ShiftRegister_ToggleTargetLEDs(CurrentTarget)
Post BeginJoySequence event to JoySequenceSM
Call ShiftRegister_ExternalLine5V(true)
Post FlagWin event to FlagService
Start Joy timer
Reset TargetToHit to 1
Else If BombsLeft is greater than 0
Set NextState to SharkOFF
Call ShiftRegister_TargetAcquiredLED(false)
Call ShiftRegister_ToggleTargetLEDs(CurrentTarget) //
switch red->grn
// Set Bomb LEDs to win & new target
Decrease BombsLeft by 1
Set TargetStatus of the target that was hit to false
Else
Error
EndIf
If ThisEvent is LaserOffDetector
Call ShiftRegister_TargetAcquiredLED(false)
Set NextState to SharkOFF
Endif
If ThisEvent is MainTimeout or AbortButtonDown
FULL_RESET
EndIf
End SharkON block
CurrentState is Joy
If ThisEvent is JoyTimeout or AbortButtonDown
FULL_RESET
EndIf
End Joy block
Set CurrentState to NextState
Return ES_NO_EVENT
End of RunDDM_SM
// Module Functions
boolean areAudioPinsAboveThreshold( void )
local variables: pin1val, pin2val
// get values from ADC_InSeq3() - will be integers from 0 to 4095
read from mic input pin 1 and store analog value to pin1val
read from mic input pin 2 and store analog value to pin2val
if pin1val > AUDIO_THRESHOLD and pin2val > AUDIO_THRESHOLD
return true
else
return false
end function
void UpdateIndicatorPosition( void )
newPosition = Duration / DURATIONMAX
Call Servos_SetServo(indicator servo, newPosition)
end UpdateIndicator Position
void FULL_RESET(void)
Call Servos_SetServo(indicator servo, 0%)
Call Servos_SetServo(shark servo, start position)
Call ShiftRegister_Reset()
Duration = 0
Bombs = NUM_BOMBS
end FULL_RESET
DDM_SM_state_t QueryDDM_SM()
return CurrentState
end QueryDDM_SM