async state machine for microcontrollers

Ive used single thread async state machines over the years in ms windows to control hardware. Now that im playing with arduino boards i would like to know if there are any libraries or discussions on implementing this pattern on an arduino. Thanks in advance. Doug

i would like to know if there are any libraries or discussions on implementing this pattern on an arduino.

That being the only "pattern" that really works on a microcontroller, what do you need a library for? Or discussion, for that matter? The whole concept is simply fundamental to the way microcontrollers work.

I guess i dont really understand these controllers. In ms sindows c++ i can use windows message dispatch, in c# i could use event-delegates. You suggest these are built in, i guess i just missed it. I thought there might be a post-dispath library somewhere but i guess i dont need it. Thanks.

You suggest these are built in

No. The Arduino runs a single thread. It is up to you to deal with events as they happen, including discovering that the events have happened.

A good example is serial data arriving. Periodically, you need to check to see if that has happened. That is where Serial.available() is useful. You then deal with (by collecting and storing) all pending serial data, until there is no more, or until the collected data represents a complete packet. Then, you deal with the collected data, and reset to be ready to collect more.

There are other asynchronous events completion tasks that trigger interrupts, such that you can provide an interrupt handler to deal with them. For instance, reading an analog pin typically takes time. You can just wait until the reading is complete, or you can use the asynchronous method (Nick Gammon has documented it) to start a reading happening and to be notified when it is complete.

Thanks, this helps. I also found

Afetr some lengthy searching.

Most of my apps can use a simple loop, but hey, i also want to have some fun programming as well.

I also found a link in playground

http://arduino.cc/playground/Code/QP

Any pros or cons on using this?

Roll your own to fit your needs, your algorithm.

Given setup() and loop() to address real time tasks, some form of state machine approach usually makes the most sense.

My code reads and evaluates serial data as it comes in, not starting after collection. I generally need less buffer space and string manipulation code. State machine method is very useful when reading and compiling data on-the-fly.

ddmcf:
... After some lengthy searching I found

QP™ Event-Driven Programming for Arduino
...

Thank You, Thank You, Thank You !
I had to read a ton of posts about 'asynchronous arduino' until I found you! (and I googled a lot about this).
Why isn't QP on the first page, beats me!