-1

We have a lot of functions that depend on while loop. After enable interrupts in one of these functions, we want to back beginning of the void loop().

Any help will be appreciated.

Thanks.

ocrdu
  • 2,172
  • 6
  • 15
  • 22
Elif
  • 141
  • 13
  • You don't understand how interrupts work. Read the datasheet and application notes. – TomServo Jan 20 '21 at 00:39
  • When a data arrives, I have to stop execution instantaneously and I need to restart the loop. Do you have a suggestion for this? – Elif Jan 20 '21 at 07:00
  • Typically, using interrupts is WRONG. Typically, using a `while` inside `loop()` is WRONG too. If loop() does not need any time, it is much faster than any data can arrive (serially, at least). Of course that applies to any function you call from loop as well. They should always return immediately. the loop can finish immediately as well and behaves as you want (return to start of loop) – datafiddler Jan 20 '21 at 09:50

1 Answers1

1

You want to go right back to the start of the loop function, from the middle of the loop function?

If i have understand it correctly, that's just not a good design, you could ofcourse add some flags variables, and statements all the way to control the flow of the program.

A good and pretty scalable way is to use either this control structure:

void loop()
{
  outcome = initStuff();
  outcome = someRandomStuff();
  if(outcome == false){return;}
  outcome = finishingStuff();
}

Or my favorite way, write it very modular. So that you don't have to restart or teleport back to the start of the function. Obviously it's impossible for me to say how, since i don't know what you are programming, BUT make sure that you code so that initStuff() in my example really contains all of the needed functionality for initing everything. Therefore you could simply call that function instead of needing to start the whole loop over incase that you have some desirable functions to pass through there.

CoffeDev
  • 258
  • 2
  • 12