Example state machine
The example below shows a working state machine, modelling a cassette player, with the current state highlighted (as this is a hierarchical machine, you will see the nesting of current state).
The example below shows a working state machine, modelling a cassette player, with the current state highlighted (as this is a hierarchical machine, you will see the nesting of current state).
The model is implemented in JavaScript as a script in the page, see the page source for details.
Use the buttons below to send triggering events into the machine for evaluation.
Below are the outputs of the state machine, in this example controlling the cassette players head and motor
Head: disengaged
Motor: stopped
Links: Github
In addition to basic state transitions, this example shows a few more advanced features: first, deep history is specified in the operational state, meaning when returning from the flipped state, the machine will revert to the state it was in prior to entering the flipped state; next, there are two transitions that respond to the Stop event, this shows depth-first evaluation; last, the transition from stopped to running crosses the region boundary within the active state such that there is no need for an initial state; last, the stopped state can defer the Pause event for evaluation after it has been exited.
The active state configuration changes colour on state entry/exit with transparency to show the nesting of the current state. If you open your browser console you will see some further log output.