You are on page 1of 2

BlinkingLED Module (a service that implements a state machine)

Module Variables: CurrentState, MyPriority, rate = 2000


InitializeBlinkingLED
Takes a priority number, returns true.
Initialize the MyPriority variable with the passed in parameter.
Set CurrentState to be InitBlinkingLED
Post Event ES_Init to BlinkingLED queue (this service)
End of InitializeBlinkingLED
RunBlinkingLED (implements the state machine for Blinking LEDs)
The EventType field of ThisEvent will be one of: EnteringDisarmingState, ExitingDisarmingState,
ES_TIMEOUT or ES_Init
Returns ES_NO_EVENT
Local Variables: NextState
Set NextState to CurrentState
Based on the state of the CurrentState variable choose one of the following blocks of code:
CurrentState is InitBlinkingLED
If ThisEvent is ES_INIT
Set NextState to LED_OFF
End if
End InitBlinkingLED block
CurrentState is LED_OFF
If ThisEvent is EnteringDisarmingState
Start Blink Timer with parameter rate for LED on/off time which posts to
BlinkingLED
Start TimeKeeping timer which expires in 10 sec which posts to BlinkingLED
Set NextState to LED_ON
Turn on the LED strip for fear
End if
If ThisEvent is ES_TIMEOUT
If ThisEvent Parameter is blink timer number
Set Next state as LED_ON
Turn on the LED strip for fear
Start Blink Timer with parameter rate for LED on/off time which posts to
BlinkingLED
End if
If ThisEvent Parameter is time keeping timer number
Set Next state as LED_ON
Turn on the LED strip for fear
Set rate = rate/2 to increase blinking speed by double
Start Blink Timer with parameter rate for LED on/off time which posts to
BlinkingLED
Start TimeKeeping timer which expires in 10 sec which posts to
BlinkingLED

End if
End if
If ThisEvent is ExitingDisarmingState
Turn off the LED strip for fear
Set NextState as LED_OFF
Stop both blink and timekeeping timers
Set rate to 2000 again
End if
End LED_OFF block
CurrentState is LED_ON
If ThisEvent is ES_TIMEOUT
If ThisEvent Parameter is blink timer number
Set Next state as LED_OFF
Turn off the LED strip for fear
Start Blink Timer with parameter rate for LED on/off time which posts to
BlinkingLED
End if
If ThisEvent Parameter is time keeping timer number
Set Next state as LED_OFF
Turn off the LED strip for fear
Set rate = rate/2 to increase blinking speed by double
Start Blink Timer with parameter rate for LED on/off time which posts to
BlinkingLED
Start TimeKeeping timer which expires in 10 sec which posts to
BlinkingLED
End if
End if
If ThisEvent is ExitingDisarmingState
Turn off the LED strip for fear
Set NextState as LED_OFF
Stop both blink and timekeeping timers
Set rate to 2000 again
End if
End LED_ON block
Set CurrentState to NextState
Return ES_NO_EVENT
End of RunBlinkingLED

You might also like