-
Notifications
You must be signed in to change notification settings - Fork 44
What is a State Machine
From wikipedia, a state machine, is a mathematical model of computation used to design both computer programs and sequential logic circuits. It is conceived as an abstract machine that can be in one of a finite number of states. It can change from one state to another when initiated by a triggering event or condition; this is called a transition. A state machine can be defined as a set of valid state transitions. These state transitions can be completely defined using a state transition table (see below). For example, consider the following state machine modelling a turnstile
(Source: Wikipedia)
Current State | Input | Next State | Output |
---|---|---|---|
Locked | coin | Unlocked | Unlock turnstile so customer can push through |
Locked | push | Locked | None |
Unlocked | coin | Unlocked | None |
Unlocked | push | Locked | When customer has pushed through, lock turnstile |
(Source: Wikipedia) |
On receiving a Push input in the Unlocked state, the state machine transitions its state to Locked. A state, thus, represents the current status of the state machine - awaiting an event to execute a transition to the next state machine. A transition is a set of actions that need to be performed when an event is received. For the above example that indicates the physical rotation of the turnstile to bring it to Locked state.