Hello,
is there a way to jump to the start of the main loop after a hardware interrupt is triggered?
No. What do you really want to do?
If have some relatively complex code which controls a robot in my main loop. I have also a switch which should imediadly stop the thing an pause it while the switch is high. Ater the swizch is low again the main loop would continue at some random place which causes some problems. To avoid thoose it would be necessery to jump to the beginning od the loop.
How "immediately" does it need to stop? Can you just poll the switch each loop (or at multiple points in loop) rather than using interrupts?
Can you post your code.
would a simple restart suffice??
void(* resetFunc) (void) = 0;//declare reset function at address 0
This works, and simply hangs in the loop until the switch is released
while (digitalRead(switchpin) == LOW) {
stop_motors();
delay(50); //ignore switch bounce
}
For beginners, use of interrupts almost always causes more problems than it solves.
You are not getting my point. My 1300+ lines of code take some time and my problem is that i just dont want to jump to the same point in my main loop after the interrupt service routine finished
The code is like 1300+ lines + header. Every loop would be not fast enough. In this the interrupt is absolutly necessary
Please post your 1300+ lines of code, in code tags please...
Poor programming practice, which leaves the system unable to respond to high priority events.
An interrupt will not solve that problem. Have fun, and good luck with your project!
If that is C code, not pseudocode, then this line does absolutely nothing:
motor_on;
unless it is defined as a preprocessor macro.
What are you up to here, are you paraphrasing? This is why you need to post the actual code. All of it.
While loops are generally blocking... so not great if you want to do things in parallel... like interpret a button press.
If we could see your code we may be able to see opportunities to streamline.
Try again, that is not a complete, compilable sketch.
without the functions
We need to see those, too.
Found a solution, thanks for your help
![]()
Sometimes 1300 just won't do. Keep making it happen.
Ugly hack to cover up poor coding structure and implementation.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.