does such code exist??

You may find some useful stuff in Planning and Implementing a Program

It illustrates the use of functions and the use of millis() to manage timing without blocking.

...R