What is a state machine?It is a way to describe what a system is designed to do (output) depending of the state is presently in. As an example, we could use an LED. An LED can only be in one of two states: {ON, OFF}. Each state is mutually exclusive of the other. An LED cannot be simultaneously ON and OFF. There has to be one of the states that have to be declared as the start state. We will also have to remember in which state the machine currently is (the current state).enum LedStates{ON, OFF}; //The names of all statesLedStates ledState = ON; //The start state (and the current state after that)

I believe that those two lines, along with the the paragraph above them is simple enough to understand.

Someone new to the state machine concept are not necessarily new to programming. This tutorial is not about C++. It is about implanting a state machine in Arduino's environment which happens to be written in C++.

I my mind, using a "switch" construct is not easier than using enum, since I have met on this site, a few persons that only uses "if" constructs, "since you can to everything with that construct" and won't have anything to do with "switch". But I insist in using it because the "switch" construct is , IMHO, ideal to describe a state machine's behaviour.

So, yes, it is a (double) leap of faith.

Jacques

Please do not send me PMs asking for help. Post in the forum then everyone will benefit from seeing the questions and answers.

I haven't done the exercises leading up to the elevator problem. I just started trying to solve it but it is tougher than I expected. Esp. the part of taking button presses and responding to them as the elevator is moving in the same direction as the request. Sounds like a queue needs to be used but I will go through the tutorials.

Hello Jacques I like Your documentation. I am teaching Electronics/IOT/Network on a 2 year programme, so I would like to hear if You will allow me to use your material. I have allready done a bit of writing and the contents looks much like what you have done. My examples are : the blinkmachine, the vending machine, the elevator, and I also like the "two hand safety machine" illustrated in this video : https://www.youtube.com/watch?v=LVToQDLEsVE

Hello Jacques I like Your documentation. I am teaching Electronics/IOT/Network on a 2 year programme, so I would like to hear if You will allow me to use your material. I have allready done a bit of writing and the contents looks much like what you have done. My examples are : the blinkmachine, the vending machine, the elevator, and I also like the "two hand safety machine" illustrated in this video : https://www.youtube.com/watch?v=LVToQDLEsVE

Hi kajnorman,

I would love to see your documentation.

Jacques

Please do not send me PMs asking for help. Post in the forum then everyone will benefit from seeing the questions and answers.

I just dove into state machines and while i am limited to programming i have some latter logic from the 80-90s of GE fanuc PLC. I think this type of "thinking" suites my personal way of creating arduino code. I am currently reviewing and trying to understand the part 1 state tutorial but got stuck.

I understand that you are giving the code the option to swtich modes dependent on pullup or pulldown but i cannot rap my head around what is occuring at each case. Can you help me understand this part of the logic?

Thanks Art, i appreciate the time to make the tutorial it has open my eyes to much simple and cleaner arduino projects.

Hello Jacques, first of all your tutorial is great. For the last two weeks I am trying to find a way for a project, I discovered State Machine and I saw that there is a solution there but now, with your tutorial I am sure that I have to walk in this direction. I would ask you please for a clue. How I should manage the state machine statement if I have more control devices, in my case I have a motor and its behavior depends of one sensor and two buttons. Sensor always start and stop, and the buttons change direction.Any suggestion will be very welcome and thank you again for the tutorial