Go Down

Topic: State machine for Arduino tutorial (Read 935 times) previous topic - next topic

jbellavance

Hi,

I just finished a 3 parts State machine tutorial.

You can find it here.
Let me know what you think about it.

Jacques
If I can help...

larryd

I do like the document aesthetics. :)

Looked at things quickly, two small 'constructive' criticisms .
- for beginners, suggest you document the lines of code so a person can more easily follow the code and your program logic.
- personally, I do not like a bunch of code all stuffed on one line. White space is free but we discussed this preference before ;).

The commenting is better in #3.

You are having way too much fun!

Great work!


No technical PMs.
The last thing you did is where you should start looking.

jbellavance

Hi Larry,

Just added the commented sketches... with a single statement per line  ;)

Enjoy, countryman.

Jacques
If I can help...

jbellavance

Part two now has a traffic light example besides the existing vending machine example.

Jacques
If I can help...

6v6gt

I looked quickly through and it appears very nicely put together.

I guess the main issue for a beginner is (a) recognising whether a specific real world problem is a candidate for the state machine approach and then (b) modelling that problem as a state machine in a systematic way.
Once that level has been achieved, the translation of the state machine model into code should be a relatively straight forward exercise.

I did a simple example for someone here and it was basic enough to describe in an excel table and I left the code more or less 1:1 with the table (although it could be optimised).

jbellavance

Hi 6v6gt,


Thanks for taking the time to look at my tutorial.

The idea of using a table is another great way to describe the machine. It is one of the tools used when designing hardware state machines where all combinations have to be adressed.

I looked at the table and the code that you suggested and it certainly works. As you have seen in my tutorial, I make the transition decisions in the state machine itself. That allows the code for each line in the table to be in just one place.

Have a nice day.

Jacques
If I can help...

Go Up