Beep Beep - 8 months ago 109
C Question

how to stop a loop arduino

I have this loop, how would I end the loop?

void loop() {
// read the pushbutton input pin:

a ++;
analogWrite(speakerOut, NULL);

if(a > 50 && a < 300){
analogWrite(speakerOut, 200);

if(a <= 49){
analogWrite(speakerOut, NULL);

if(a >= 300 && a <= 2499){
analogWrite(speakerOut, NULL);


Arduino specifically provides absolutely no way to exit their loop function, as exhibited by the code that actually runs it:


for (;;) {
    if (serialEventRun) serialEventRun();

Besides, on a microcontroller there isn't anything to exit to in the first place.

The closest you can do is to just halt the processor. That will stop processing until it's reset.