I need help. Please,

I recently started working on transforming manual medical Treadmill that gets manually adjusted to a one that’s controlled by buttons for every stage of it
That means programming The Servo Motor and the other speed motors to change speed and oblique heights
Anyway I needed A stop button that can stop the Machine in the middle of any stage because sometimes patients start to get exhausted
So again I need A stop button that can stop the machine at any time please answer me quickly because i need it soon
I’m a beginner So please bear with me

#include <Servo.h>
Servo myservo;
int DcMotor1=A0;
int DcMotor2=A1;
int ResetButton=(13);
int StopButton=(12);
int St1Button=(10);
int St2Button=(9); 
int St3Button=(8);
int St4Button=(7);
int St5Button=(6);
int St6Button=(5);
int St7Button=(4);
int St8Button=(2);
int St9Button=(1);
void setup() {
  // put your setup code here, to run once:
myservo.attach(3);
pinMode(DcMotor1,OUTPUT);
pinMode(DcMotor2,OUTPUT);
pinMode(StopButton,OUTPUT);
pinMode(St1Button,INPUT);
pinMode(St2Button,INPUT);
pinMode(St3Button,INPUT);
pinMode(St4Button,INPUT);
pinMode(St5Button,INPUT);
pinMode(St6Button,INPUT);
pinMode(St7Button,INPUT);
pinMode(St8Button,INPUT);
pinMode(St9Button,INPUT);
}

void loop() {
if(digitalRead(ResetButton)==HIGH)
{myservo.write(0);}
if(digitalRead(St1Button)==HIGH)
{myservo.write(4);
analogWrite(DcMotor1,28);
analogWrite(DcMotor2,28);
delay(900000);
analogWrite(DcMotor1,0);
analogWrite(DcMotor1,0);}
else if(digitalRead(St2Button)==HIGH)
{myservo.write(8);
analogWrite(DcMotor1,56);
analogWrite(DcMotor2,56);
delay(900000);
analogWrite(DcMotor1,0);
analogWrite(DcMotor2,0);}
else if(digitalRead(St3Button)==HIGH)
{myservo.write(12);
analogWrite(DcMotor1,84);
analogWrite(DcMotor2,84);
delay(900000);
analogWrite(DcMotor1,0);
analogWrite(DcMotor2,0);}
else if(digitalRead(St4Button)==HIGH)
{myservo.write(16);
analogWrite(DcMotor1,112);
analogWrite(DcMotor2,112);
delay(900000);
analogWrite(DcMotor1,0);
analogWrite(DcMotor2,0);}
else if(digitalRead(St5Button)==HIGH)
{myservo.write(20);
analogWrite(DcMotor1,130);
analogWrite(DcMotor2,130);
delay(900000);
analogWrite(DcMotor1,0);
analogWrite(DcMotor2,0);}
else if(digitalRead(St6Button)==HIGH)
{myservo.write(24);
analogWrite(DcMotor1,158);
analogWrite(DcMotor2,158);
delay(900000);
analogWrite(DcMotor1,0);
analogWrite(DcMotor2,0);}
else if(digitalRead(St7Button)==HIGH)
{myservo.write(28);
analogWrite(DcMotor1,186);
analogWrite(DcMotor2,186);
delay(900000);
analogWrite(DcMotor1,0);
analogWrite(DcMotor2,0);}
else if(digitalRead(St8Button)==HIGH)
{myservo.write(32);
analogWrite(DcMotor1,214);
analogWrite(DcMotor2,214);
delay(900000);
analogWrite(DcMotor1,0);
analogWrite(DcMotor2,0);}
else if (digitalRead(St9Button)==HIGH)
{myservo.write(36);
analogWrite(DcMotor1,255);
analogWrite(DcMotor2,255);
delay(900000);
analogWrite(DcMotor1,0);
analogWrite(DcMotor2,0);}
}

I just need a stop button

There is such a switch on the treadmill at my plant. It is a plastic plug on a string. The string is fastened to clothing so if a fall or exhaustion, the plastic plug is pulled out of the switch and ALL the power is immediately shut off. The machine can't run without the plug.

Your solution should do the same.

Paul

How about a big 'ol mechanical stop button (switch) that cuts the power? That's what you'll typically find on industrial machines. If your software crashes or locks-up or goes haywire you can't trust the software to read the switch.

The delay() essentially pauses your program so you can't read any buttons/inputs until the delay() is over. An interrupt might work but it's not as reliable as a power-kill switch.

It's fairly rare to find delays in "real" programs although short delays (a few milliseconds or microseconds) can be OK, or there are applications where the program truly doesn't need to do anything during the delay.

For timing/delays without using the delay() function, you can also study the Blink Without Delay Example or study the post at the top of the forum about doing several things at the same time.

Note that anything for "medical use" is highly regulated. And, there's usually a "Not for medical use" disclaimer for microprocessors and other electronic components. (I don't know if there are such disclaimers for the ATmega chip or the Arduino.) Of course, people (companies) still use them in medical applications but you can't sue the chip manufacturer if the chip fails and someone gets injured or killed. You can be sued because you made something dangerous and you used something not approved.

Guys if I made a Power kill switch that kills power completely AND suddenly doesn't that harm the arduino chip

What I meant is more like a pause button

pinMode(StopButton,OUTPUT);

Really? An output?

How are your buttons wired? It is much more common to see INPUT_PULLUP for buttons.

You have to get rid of the long delays. Look at the BlinkWithoutDelay example and start again.

Your code is difficult to read because there is no indentation. Use the auto-format function in the editor. It is very good. If it appears to scramble your code then the code is wrong.