Upload mode / Arduino / _delay


Hi Everyone

Can anyone give me a definitive answer as to what the second loop ( _loop ) actually does when it is called in mBlock’s useful default Function ( void_delay ) shown below? Is it just an empty loop for timing purposes perhaps? I know that void_delay is useful because it is not a ‘blocking’ call that will halt all programme execution until the ‘wait’ period is over.

void _delay(float seconds) {
if(seconds < 0.0){
seconds = 0.0;
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();

I have experimented by deleting the void _loop Function and removing the one reference to it in the void _delay Function; and on running this simplified code it still seems to work quite happily without _loop being present. N.B. The last line of my simplified void _delay code now reads as follows:

while(millis() < endTime);

Is there anything wrong with the logic of this?

Occasionally, I have seen code fragments from other forum members shown with code added inside the void _loop Function. Is this a good idea?


Personally I only program my mBot using the Arduino IDE and write my own code. I have seen the code you me tuin and indeed it has to do something with timing. And yeah indeed most of your code (99%) will run fine without it. I never use it and never accounted any issues. If you want to know more about I suggest you to take a look on the Arduino.cc forum


Hi Atonbom

Thanks for your response- I’ll try the Arduino.cc forum. I’m trying to analyze exactly how the mBlock5 IDE works for another book.