In the previous two parts, I have shown how to build a 2-way traffic light and how to write a sketch to control it.
This time we’ll rewrite the sketch to use state tables.
In microcontroller programming, we are often dealing with a set of well defined states. State tables describe what each state means, rules for transitioning between the different states, for what is allowed and what is expected. Keeping this in a set of tables helps keep the code simple by avoiding a big, tangled mess of if-else statements. This, in turn keeps the code smaller so we can do more with the rather limited memory on the microcontroller.