 # PUSH Button START/STOP

Hello world,

I am looking to add a start/stop function to my program so I can control the program and not have the void loop continuously running the same program.
Here is my program:

#define DIR_PIN_X 2
#define STEP_PIN_X 3
#define DIR_PIN_Y 4
#define STEP_PIN_Y 5
#define DIR_PIN_Z 6
#define STEP_PIN_Z 7

void setup() {
pinMode(DIR_PIN_X, OUTPUT);
pinMode(STEP_PIN_X, OUTPUT);
pinMode(DIR_PIN_Y, OUTPUT);
pinMode(STEP_PIN_Y, OUTPUT);
pinMode(DIR_PIN_Z, OUTPUT);
pinMode(STEP_PIN_Z, OUTPUT);

}
void loop(){
//rotate a specific number of degrees
rotateDeg_Z(2000, .75);
rotateDeg_X(1000, .7);
rotateDeg_Y(1000, .7);
rotateDeg_X(-1000, .7);
rotateDeg_Y(-1000, .7);
rotateDeg_Z(-1000, .7);
//rotateDeg_X(1000, .7);
}

void rotateDeg_X(float deg, float speed){
//rotate a specific number of degrees (negitive for reverse movement)
//speed is any number from .01 → 1 with 1 being fastest - Slower is stronger
int dir = (deg > 0)? HIGH:LOW;
digitalWrite(DIR_PIN_X,dir);
int steps = abs(deg)(1/0.225);
float usDelay = (1/speed) * 70;
for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN_X, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN_X, LOW);
delayMicroseconds(usDelay);
}
}
void rotateDeg_Y(float deg, float speed){
//rotate a specific number of degrees (negitive for reverse movement)
//speed is any number from .01 → 1 with 1 being fastest - Slower is stronger
int dir = (deg > 0)? HIGH:LOW;
digitalWrite(DIR_PIN_Y,dir);
int steps = abs(deg)
(1/0.225);
float usDelay = (1/speed) * 70;
for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN_Y, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN_X, LOW);
delayMicroseconds(usDelay);
}
}
void rotateDeg_Z(float deg, float speed){
//rotate a specific number of degrees (negitive for reverse movement)
//speed is any number from .01 → 1 with 1 being fastest - Slower is stronger
int dir = (deg > 0)? HIGH:LOW;
digitalWrite(DIR_PIN_Z,dir);
int steps = abs(deg)*(1/0.225);
float usDelay = (1/speed) * 70;
for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN_Z, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN_Z, LOW);
delayMicroseconds(usDelay);
}
}

Not hard:

``````void loop(){