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:
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.