Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The example below demonstrates a the same simple FSM using the switch statement, and one variable to store the state.

...

If you use an FSM library for Arduino, you can use some more advanced features such as enter, exit and transition functions that might be useful for organising your code and for solving some more specific challenges. For example, you can use the enter function to record a timestamp, then use the exit function to print out over serial how long the Arduino was in a given state based on the timestamp. You can also code behaviour for entering and exiting a given state.


It’s also common to see an enumeration declaration used to keep track of states.

...