To keep record of Finite state status, the following state modes are defined: 







State is not active



State was executed in the current cycle and will be in the next



State will be executed in the current cycle


Pending to run

State will be executed in the next cycle of the main loop


It is important to understand the meaning of a "cycle". The loop part of the sketch will be repeated endlessly.  Part of the loop is the execution of the FSM cycle. In every cycle all active FSM states will be executed. The handling of the states are according to the following: The cycle is running through all defined states. When a state is in running mode (RUN) the code of this state will be executed and at the end the state's mode is put on computing (COM) or when TransistionToState is called (once or more times) in the code of the running state, the state is put on hibernate (HIB) and the state to goto is set on pending (PEN).  At the end of the cycle -when the sketch has run trough all defined states- all computing (COM) and pending (PEN) states are put on mode RUN (running). And now a new cycle is started again.  

With the standard sketch it is also possible to have more than one FSM running. So it is possible to run more sequences in parallel (multitasking). The start of an extra FSM is possible from any other FSM (for example direct from the "START" state). See also function TransitionToState. When working with more than one sequence, it is of course possible to “communicate” between these sequences. When communicating between sequences, exchange only control information. Exchanging data between states is not recommended. Use some sort of master/slave communication for communication between finite state machines.


For handling the states, every state keeps a record for administration purposes, e.g. the name, the state number (PID, Process IDentification), total run time, the actual state and the threador sequence number. The state of the records can be viewed in the serial monitor (see chapter 6). The only thing to do is calling the function TransitionToState("<statename>") to go to another state. TransitionToState called one time from the current state takes place in the same thread or sequence. When TransitionToState is called n times from a finite state, the sketch starts n-1 extra sequences. Remark: an already running state cannot be started again while active. So a call of TransitionToState to an already running state is not effective (also not harmful). A transisition to the standard "END" state, puts the state on HIB.


  • When there is just one active state with a transit to the "END" state, it will kill the FSM.
  • When calling TransitionToState to activate another state, while keeping the caller state also alive; call TransitionToState also for the caller, otherwise it will go standard on HIB.


[1] Temporary status, only visible during debug actions

[2] A sequence is a thread of connected states and transitions.