(I am not English so sorry for mistakes, I think I am writing clearly)
My problem:
I have loops, but at some point in my program I want it to end and no condition can resume it. Is there any way to ignore any loops for the reset of the arduino board?
yes
1 Like
You can use a flag variable
bool okToLoop = true;
Then to turn off your loop
okToLoop = false;
then your loop
if (okToLoop) for (. . . .
will only run if it is ok. Hasn't been turned on off.
Just don't turn it on again, so to speak. And the loop won't run.
a7
Make your loops conditional by adding an "if.... " in front of the loop. If false, do the loop. If true, don't do the loop.
Like others have said, but I have my own method of doing it:
bool running = true;
void setup() {
}
void loop() {
if (running) {
// put your looping body in here
// when you reach the end of your program,
// set running = false
}
}
It's a very simple and good idea, thank you! @er_name_not_found
1 Like
Note, you can also add a code snippet outside the if to monitor a button or interrupt to set running back to true for other programs in the future.
1 Like
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.