I am having difficulties with my state machine. I use a function that returns the new state based on input parameters oldState and two input parameters.
In this function I have a lot of nested switch cases. I’d rather use a 2×2 transition matrix but have no idea how to use it. I did make a transition table from the state diagram with sates and inputs.
But how exaclty do I use the 2 dim. array transition_table[3][4]?
You stated you currently have something like this:
So, it seems what you need is a 3-dimensional array:
Then you would transition like this:
So, assuming that
StateIndex(StateC)returns2, then:would result in
new_stateholdingStateK.