I put the order exit(0); at the end of my loop to stop Motor DCC when my vehicle arrive at destination. And I would like to know if it's possible to restart the loop with (in my example) a microphone who recognizes the sound defined before.
Yeah but my programm is : when the distance measure is under 15cm the motor turn off but when this distance passes over 15 cm the motor turn on, and I want my motor turn on only when the microphone hears the sound.
I can't do a for endfor or a while endwhile because I've the Distance_A , the ultrasonic sensor calculated the distance everytime so If I do a for endfor , it will stop the calcul of the distance
I put the order exit(0); at the end of my loop to stop Motor DCC when my vehicle arrive at destination. And I would like to know if it's possible to restart the loop with (in my example) a microphone who recognizes the sound defined before.
In C/C++ functions are called, and the return back to the caller when they have done what they are designed to do.
exit() is a function just like any other function like loop() setup() digitalWrite() etc...
However, exit() is a bit special in that it is built in function provided by the C compiler library that does not return.
When exit() is called in Arduino, the processor goes into a hard loop that never returns.
In a system with a real operating system, exit() would exit the program and return control back to the parent process.
But since there is no OS and no parent process in an embedded system like Arduino, the exit() function just spins and loops forever, effectively halting the processor.
In Arduino, the C main() function calls loop() over and over again.
if you have a condition and want to return from your loop() function somewhere in the middle of your loop() code rather than at the bottom, simply use:
return;
That will return from your loop() function back to main() and the Arduino provided main() function will call loop() again, which effectively "re-starts" loop.