i keep wondering why the built in standard 'delay ();' function hasn't been changed to a non blocking delay function.
i can see when searching that there are many libraries / functions offered with non blocking delays, and i can vaguely remember a way of using the milli's function.
But they all seem to need quite a few bits of code to use,
I'd have thought it may be easier for beginners (and people like me who forget stuff) to be able to simply type something like :
'nonBlockingDelay (1000);
when they just want a simple delay for say flashing a led, or sending repeating keyboard key's at a speed the computer can keep up with.
One very accepted standard is to create a series of timed events using millis() for timing. There are dozens if not hundreds of threads about it. It is not as simple as using delay, but it's not too complex for most applications either.
delay()'s whole purpose is blocking code from proceeding to the next line. For simple scripts, it is indeed easy, right up until the point you want to do more than one thing, when un-tangling the interactions between delay()s (and for(...)s, while(...)s, etc.) makes things much more difficult.
these are two complete different programming paradigm, which can't be easily solved with the exchange of a simple keyword like "nonblockingdelay()"
delay() does what it says - it delays further execution of the next user line of code.
one variant to avoid blocking is "Blink Without Delay" - do things when they are due to do.
I highly recommend to study Blink Without Delay.
Study it as long as it takes so you can write down the blinking code by heart.
Afterwards you can apply that concept for any non blocking time management you need.
If you were using RTOS you could let run several tasks in parallel and each could have its own delay. But on a small arduino, you are better using "Blink Without Delay" - using millis()
If that is all you want to do there is no benefit in using non-blocking code.
Its only when your requirements become more sophisticated that non-blocking code is needed.
And in those cases you need to plan the way processor time is handled, and use a timer (eg millis) to control it.
I followed the link but I see no explanation of the code or the way the TaskDelay macro works.
And yes I googled for it - +"taskDelay(millis)" arduino - with no results.
There are two options. The pthreads library offers a form of non-blocking behavior but it can be difficult to beginners to understand.
Or you can move to a more modern processor like an ESP32 or an STM32 that can run FreeRTOS. A multitasking operating system that can manage running multiple threads at once. It's far easier to use than people seem to think and it immediately solves the problem you have.
I don't see what you are telling us to look at. I do see many task library solutions SimlpleTaskManager, TaskManager, TaskSheduker and so forth.
Seems like it's been solved to death. One wonders why we almost never see anyone actually using those libraries in an UNO.
Whether or not one uses a library, I think it is valuable to at least once come fully to grips with blink without delay, and how that pattern can be leveraged into directly coding the performance of multiple things at once.
By writing something that does a few things at once using millis(). No library, no easy helper functions, no language features you wouldn't know after the first few steps into programming.
The few I've looked at don't do what I want and looked harder to use for what they did that I could make any use of than just writing it myself, or getting it from a previous sketch nearly wholesale.
@alto777, @DrDiettrich and others:
All of the above discussion of Multi-Tasking is totally inappropriate given that the OP is apparently a newbie who has not yet mastered basic millis-based non-blocking code. Any other Multi-Tasking technique is at least an order of magnitude more complex.
The original question was, "Is there a non blocking delay that 's as easy to use as the built in delay function?".
The short answer is, "No, because moving past delay inherently implies some form multitasking." One can't simply insert some "nonBlockingDelay()" without also specifying what code can and can't run during the delay period and providing some mechanism for exiting the delay period.
Thus how one does multitasking seems an appropriate response albeit starting with the BlinkWithoutDelay() is probably the most appropriate first step on this journey.
Multi-tasking becomes complex only if inter-task communication is involved. Newbies typically have the other problem, that tasks should not interact and that's what Task Macros can do.