Emergency function

Hi all, I am doing a project that requires to run a system test (linear actuator moving) for hundreds of time and I would need an emergency function to stop the test at any time/instant that I want. Can anyone helps me with the coding part? Because I don’t know how to do an interruption to that program.

Emergency functions are normally done with hardware if for safety purposes.

BIG RED BUTTON.

if (switch_pressed)
  stop_doing_what_you_were_doing ();

Can anyone helps me with the coding part?

Let’s see what you have so far. Does it include the use of delay() by any chance ?

I am using switch case to do multi-tasking(e.g. moving a linear actuator), how do I be able to pause the task at any instant where I press the pause button ? And then the user is allowed to press any buttons to continue doing what they want?

my basic idea is

int pinArray={buttons.........};
boolean Pausing=false;
boolean ExitPause=false;

void setup(){
pinMode(button1, OUTPUT);//assume the case is a button
pinMode(button2, OUTPUT);
pinMode(buttonN........);
}

void pause function(){

digitalWrite(pinArray,LOW);//each function in the case will stop
delay(100);
Pausing=true;
ExitPause=false;

}

How can switch case be brought into array? And my idea does not fulfill the requirement of pausing at any interval where the user presses the pause button (I am using capacitive touches modules for all the buttons including pause button).

Thanks

I am using switch case to do multi-tasking(

Not in
the example pseudo code you posted, you're not.

Without a clear idea of your program structure, it's going to be difficult to offer advice.

Can I use interrupt to create a pause function? The most important thing that I am concerned is pausing at the middle when the system is running.

Can I use interrupt to create a pause function?

Why would you want to ?
Write the program in sucha way as to ensure that the loop() function is not blocked from running, which means no use of the delay() function, then at each iteration of loop() you can check whether the pause button has been pressed since the previous check and if it is, act on it.

Written properly the loop() function repeats thousands of times per second, so there is no need to use an interrupt, and in any case you would need to react to the interrupt in loop() so why not read the pause input there in the first place ?

Why do you need to use interrupt ?

Is this a theoretical AKA homework question ?

Have you been told specifically to explore interrupts ?

Have a look at the demo Several Things at a Time and at Planning and Implementing a Program

If there are ANY safety implications associated with your "emergency" then you should use a BIG RED SWITCH to cut power to the device first and then let the Arduino know.

...R

Would it not be easier to you put a switch between your Arduino and whatever is powering it, and when you need it to stop, you cut off its power, and when you want it to run again you give it its power back?

Robin2:
Have a look at the demo Several Things at a Time and at Planning and Implementing a Program

If there are ANY safety implications associated with your "emergency" then you should use a BIG RED SWITCH to cut power to the device first and then let the Arduino know.

...R

Additional conventions for the E-STOP button are that it is NC (normally closed) so that you know if the wire to the button breaks, and that it latches open.