I started playing with the idea of a state machine a few weeks ago and at this point I have a functional one. Not surprisingly, The states of the machine are modelled as c++ object instances with the type of state defined by the class of the object.
I am a big fan of interpreted languages (like python) for this kind of stuff but I do not imagine you could get a lot done with a python interpreter loaded on an Arduino. I did want the flexibility of being able to define states easily and potentially dynamically. To that end the state machine loads itself from an XML definition (I used TinyXML to parse this definition).
Loading state from XML is kind-of interesting ... while testing the basic state machine I was loading the states dynamically from the serial monitor ... it raises interesting possibilities for re-programming the device remotely.
There is definitely an overhead cost to parsing the XML and maintaining a hierarchy of state objects ... it works well but this whole idea may need to be optimized or totally re-evaluated for memory consumption if the device gets very sophisticated.
So far I have a few states (for testing):
- A menu state that is a holder allowing navigation through a hierarchy of states,
- An LCD backlight state for toggling the display backlight
- An LCD Test state that runs through the capabilities of the LCD display.
- Trinket
- 2x16 LCD display (salvaged from a previous project)
- 3 buttons (taken from a PS-2 mouse)
- an 8 ohm speaker + resistor (taken from a cordless phone)
- 9 volt battery connector
- 4 pin RGB led's
- older bluetooth shield,
- temperature sensor,
- motion sensor
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.