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?