I use duffs device to concurrently read and debounce multiple inputs in my old dj midi controller
Can you provide an example? We use state machines all the time, but I have not seen a good example of mixing other flow control statement into a switch/case outside of Duff's Device.
That code does timer, radio clock decoding, scrolling, blinking and all that using multiple 'protothreads'. As you can see the main loop sleep() and wait for a timer interrupt (or anything) to fire to wake up, so it's not even running most of the time; only when the 'tick' timer fires.
[0] https://gist.github.com/buserror/9407adb6d52153e16caad5e8a08...
A full explanation of how it works is here: http://dunkels.com/adam/pt/expansion.html
Its actually a really simple and beautiful. I worry that we give up a lot of this sort of flow expressiveness in more modern languages like Rust.
This is really cool.
*to = *from++;
while it should be *to++ = *from++;