The Arduino docs explain yield()
at https://www.arduino.cc/en/Reference/Scheduler with regards to the Due. Apparently it is part of the Scheduler library:
#include <Scheduler.h>
However, I can call yield()
on my Nano or ESP8266 without including the Scheduler lib -- but only in my main program, not inside include files. Also, the include does not work on my non-Dues.
What's the secret that I'm missing about yield()
or- what does yield()
do on Arduino platforms other than Due?
The
yield()
function is also implemented inside the ESP8266 libraries:That's why you can call
yield()
from within your main program where the ESP8266 header is included.See ESP8266 Thing Hookup Guide.
Update:
yield()
is defined in Arduino.h as:yield()
is also declared inhooks.h
as follows:So, on the
Nano
, it probably does nothing (unless you have other libraries#included
).yield is a "weak" function from Arduino core for AVR. I see one call for it inside wiring.c.
This means that the yield() function will be executed during the loop of delay function. Thus, yield would be used for some background processing while the delay ends or for doing a function with timeout feature.
Note: yield must be defined in application/sketch
UPDATE: The question made me excited to make a little post about yield and other hidden features from arduino core.