State Machine Library
Over the last few weeks I've been struggling with processing and understanding how to write a state machine. I came across a tutorial by the "Grumpy Old Tech" which takes you through a simple 'Flash' State Machine using their own State Machine Library - "GOTStateMachine".
Below I've taken some notes from this tutorial:
Firstly its important to add the library itself, this is done by downloading the Zip file containing the cpp and header files from GitHub. Then in the Arduino IDE go to Sketch/Library/Add .Zip Library.
States can be implemented like functions with the state name, e.g "void ledOn()". It is within the actual function that we actually execute the state logic and implement any state transitions.
In the setup, this is where the state machine should be initialised by setting its startState.
The State Code:
Written like a normal function - void ledOn/off () in that space you write the code as normal. Then in the transitions aspect can be written in the forms of if statements as shown in the video. You might want to include a delay period. From this you can then change the state.
I need to identify what states I need, are the states for the motors or for the LED Matrix wording. How many states will I need? Will there be 12 states or an array for messages?
Draw up the expected logic and experiment with the State Machine Code