So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By renegade
#73699 Hi all,

I keep hearing about yield, and delay();

delay() is obvious, it sleeps the main thread after the specified time it jumps back to work.

yield() appears to work background processes.

So, my question is, in my loop(), should I call both yield and delay? Or just delay?

Additionally I have heard the delay calls yield(), but I don't know if that's true! Advice and best practices please.
User avatar
By McChubby007
#73704 There are 2 contexts, one that loop is called from, and the other one which is for the system/sdk/wifi etc.

Calling yield from the loop context saves the current stack and then executes the 'other' context, which will be the 'system' context, it then returns to the saved (loop) context when it has finished any pending work. That is why the link in the previous post states that yield cannot be called from the non-loop context, as that is not how it's designed to work as where would it yield to?

Delay calls yield until such time as the delay has expired and then returns to the delay() calling function.

That's how I understand it from my distant memory.