3 ms·
You may be in for a treat if you haven't already come across protothreads [0]. They provide a form of stack-less, co-operative multi-threading and are aimed at
by dpwm 7y ago
You may be in for a treat if you haven't already come across protothreads [0].
They provide a form of stack-less, co-operative multi-threading and are aimed at microcontrollers.
I came across them by chance, and have used them on an ESP8266 – it's really made everything feel much more clear and far less confusing.
You do need to wrap your head around the trick, but that really shouldn't take long. You also need to put any state that you expect to be preserved between calls of the function into something more persistent – just like with state machines. The examples all use static variables, but I am happier using a struct pointer to maintain state.
[0] http://dunkels.com/adam/pt/ http://dunkels.com/adam/pt/