I often encounter many problems when I have to implement a "behaviour" in a microcontrollor. For example, I have some analog/digital inputs and some user commands. Based on that, the logic should set some outputs (digital or analog).
Most of the time you (the developer) must understand what is the good behaviour of the machine, because noone is able to describe it in a good way. I usually heard the sentence: when the user presses the ON button, you switch on the engine. After some short implementation, you understand that the engine should be on only if the interlock input is closed. And so on...
I think the best method to describe a machine behaviour is a state-machine, mainly a hierarchically state-machine (HSM). Do you agree?
My post here is to understand if you really use HSMs to describe the beahviour of the system you are coding and how do you implement them in C or C++ (or whatever).