Go Down

Topic: Finite State Machine Using Switch Statement. (Read 9 times) previous topic - next topic

Jack Christensen

My none-Arduino project to drive several power LEDs includes the user interface as state machine here http://code.google.com/p/tinyledlight/. The state machine is implemented with switch case statements and is available here: http://code.google.com/p/tinyledlight/source/browse/v2/tiny_led_light_v2.c

Nice state diagrams! What did you use to draw them?
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Jack Christensen

the more i search and trying to understand what is Finite State Machine, the more i understand and the more i realized how much i need to know when it come to programming . however i cant help but to see the similarity between Finite State Machine with the step sequence that i use to used when programming PLC

The first job then would be getting comfortable with C/C++ then. OO coding isn't needed to do decent FSMs. Start with something simple, three or four states at most. Being able to understand the problem at hand and visualize it in terms of states can take a little practice, but usually comes pretty quickly.

Lots of examples are available, several have been offered in this thread. A lot of good FSM exercises can be done with an Arduino, some switches to represent inputs, and LEDs to represent outputs. I'll offer one more at the risk of giving you more examples than you can enjoy, it's an implementation of the common garage-door controller project that a lot of folks have done. At this point it only senses the state of the door and lights up some LEDs accordingly, and just needs two switches and some LEDs to implement. I think it has four or five states at most. Not much code, and I also have state diagrams and tables to go with.

You can think of other examples and invent your own exercises. Lots of things in everyday life can be seen as FSMs. Appliances like washing machines go through a series of states and control valves and pumps. Traffic signals and crosswalks. See Wikipedia's article for a simple FSM representing a turnstile.

I've never programmed a PLC, but yes I wouldn't be surprised if there were a lot of similarities, so you probably have some good background there in thinking about the inputs, outputs, and states that represent a system.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/


yes thank you. The more i study what is Finite State Machine, the more i realize that most of its logic had been teach to me by my sensei. I actually use it b4 during my time working in the automation industries which actually give me some credential as a programmer back then, but that was only in ladder diagram and PLC. And yes as we speak i actually have been trying various task that i used to do while i was working. wow this really open up my eye to a whole new work of possibilities. I mean b4 i uses to think that PLC and arduino style programming have very little similarities but now, WOW!!! and i really mean WOW!!!!! all this actually click in my head rite now.
for instant now i can see how i could actually program a whole machine with this knowledge alone. 


Understanding the FSM is a bit like finally getting the blink without delay example. Once you see it, there's very much a feeling of "Is that it?". Before that though, it seems baffling, especially in the abstract. Examples help - a lot.


one thing about PLC is that every thing is represented with HIGH and LOW. which really help. with arduino the possibility to represent something as HIGH and LOW and everything in between, WOW now everything i learn from my sensei could finally put to use. He thought me about Fuzzy logic and Sequence step, timing diagram. then he thought me some automation and finally b4 i when to work he thought me about Finite State Machine, although at the time he did not tell me its name just that it is an advance form of Sequence step. but now everything make sense now. So Thank you all for actually making me realize that my sensei had thought me all of this all along. Urm you know suddenly i have the confident in me to actually do any advance work with arduino.
Again i cant stress enough how much I'm Thanking all of you.... thank you thank you thank you ......

Go Up