DaveX
September 8, 2024, 1:49am
3
You might like to learn state machines. They help simplify the code from a number of interacting logical variables (SredLightOn, ...) into a structure of mutually exclusive states (enum {ALL_RED, NorthGreen, NorthYellow, SouthGreen, SouthYellow,...}) that helps manage lots of the conditional logic.
Hello everyone,
On this gray day, considering the number of questions that boil down to programming a finite automaton (or a state machine), I thought I would translate my small tutorial I also have in French to explain how to approach this type of code in a structured manner. Of course, there are libraries that do this more or less for you, but understanding how it works can often allow you to do without libraries that might weigh down your code.
The general idea is to write a program that co…
or
A common response to “I want my code to do A., then B., then C., etc.,” from the knowledgeable is “Use a state machine.” Many who are new to coding/programming have never heard of a state machine , although almost everyone is familiar with the concept. There are different ways to realize a state machine, like the very similar Sequential Function Chart , a construct used in Programmable Logic Controllers , but this discussion will deal only with the C++ switch/case construct - which is described bri…