Hi there!
I am an arduino novice.
After browsing for a couple of hours and still not finding a way to jump back to the beginning of the loop() after an interrupt I would be very glad if someone could point me in the right direction.
My problem and code (very simplified but I hope it helps to see more easily where my problem is) follows:
Problem:
I have a motor doing a couple of things part1, part2 and part3, then it waits a bit and starts again.
Every now and then, there is an interrupt signal coming in.
When that happens, the motor successfully stops what it was doing and does motorDoesStuff() instead.
But when it has finished the void interrupt_signal, it continues finishing part1, part2 and part3 - depending on where it was interrupted.
But I want it to go back to the start of the loop and NOT finish what it was doing but start fresh with Part1 once it gets the signal.
Very, very appreciate any help!!
Simplified code:
#include <PinChangeInt.h>
/// setting lots of variables amongst which the interrupt pin
const int interruptPin = A0; ///to set the interrupt pin
//// setting a lot of FUNCTIONS for the motor do to certain things
int motorDoesSetupStuff(){
...
}
int motorDoesA_part1(){
...
}
int motorDoesA_part2(){
...
}
int motorDoesA_part3(){
...
}
int motorDoesStuff() {
...
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// start serial communication
Serial.begin(9600);
// many pins for a rotating stepper motor and a linear stage are being initialized []
/// interruptPin
pinMode(interruptPin, INPUT);
digitalWrite(interruptPin, LOW);
PCintPort::attachInterrupt(interruptPin, interrupt_signal, RISING);
motorDoesSetupStuff();
}
////////////////////////////////////////////////////////////////////////////////////////////////
void loop(){
motorDoesA_part1();
motorDoesA_part2(); /// the interrupt happens at some point while the motor does stuff
motorDoesA_part3();
}
//
void interrupt_signal() {
////
motorDoesStuff();
/// AND NOW I DON;t WANT THE MOTOR TO GO BACK TO WHAT IT WAS DOING WHEN IT WAS INTERRUPTED BUT TO START THE void loop() from the BEGINNING!!
//
}