Delay(), vs "soft delay" [end of discourse]

Hi @Jack

I think you are trying to enforce a philosophical point and not a technical one here. This is classic cooperative multi-taskting where any subroutine that blocks will disturb the cooperation and penalize the other subroutines. That doesn’t mean however that your spec is required to be “no delays in subroutines” and on the contrary a perfectly valid spec might be delays up to 10ms are allowed in any particular subroutine.

The delay can be whatever is acceptable in your application, ranging from the code minimum execution time up to any maximum you choose. If you are philosophically attracted to minimum delay, that’s great, but it is not the only valid approach. Different programmers are going to address this in different ways.

Whether the cooperative subroutines are called by loop() as a scheduler or by a timer interrupt is really just a preference. @peekay123 hybrid scheme of using timer interrupts to call the 1 millisecond task that then dispatches based on a count is just small refinement (and clever!).

There are a lot possible “right” answers here and I am glad you found yours, but that does not rule out other options for other applications.

2 Likes

I appreciate your input, and learn from it.
I did not intend to say anyones code is bad (actually the opposite). There are many ways to code. I just try to learn, and offer my opinion, hoping others will offer their opinion, so I and others on the forum can learn more. Please, nobody take my questions/comments as offensive.
Thanks, Jack

3 Likes

in my opinion, as I had said, some short delays would not be so bad, and if I only run one process/function any delay would be OK.
As the title of this thread "Delay(), vs "soft delay".
What do you think? Do you use the delay() command a lot?

I agree, a 10ms delay would not be a problem in most cases. But a delay(7000) in the "toggleLed" function, would be a problem for the "checkForDoorOpen" function to be blocked that long.
Respectfully, I disagree that this thread is more Philosophical than technical. I was told above in this thread that the pseudo code will not work using delay(), so I think of it now as technical. Thanks for all your ideas and input.