Start + Stop buttons for stepping motor

Start + Stop buttons for stepping motor
Good day, I’m just new here in the Arduino forum.
But I’m still new to the Arduino world have still been a question.
I currently have a project with 2 buttons and a stepper motor.
Controlled the whole a Arduino Mega and a Adafruid Motor Shield.
Now my problem is I can do it though with the start button, the engine of his 150 steps but do want to have a final position or as an emergency stop button.
Now, if I want to start up the motor to stop it other than a button prematurely.

my code:

include <AFMotor.h>

AF_Stepper engine (200, 1);
int button1 = 52 / / button1 - is initialized to pin 52
int TasterStatus52;
int button2 = 50 / / button2 - is initialized to pin 50
int TasterStatus50;

void setup ()
{
pinMode (button1, INPUT); / / button1 - 52 pin as input
pinMode (button2, INPUT); / / button1 - 52 pin as input
Serial.begin (9600) / / set up Serial library at 9600 bps
Serial.println (“Stepper test!”);

motor.setSpeed ??(30) / / 10 rpm

}

void loop ()
{
TasterStatus50 = digitalRead (button2);
if (TasterStatus50 == HIGH)
{
motor.step (150, BACKWARD, DOUBLE);

TasterStatus52 = digitalRead (button1);
if (TasterStatus52 == HIGH)

motor.release ();
}

Hope someone can help me that would be really great!
Thanks in advance.

Now my problem is I can do it though with the start button, the engine of his 150 steps but do want to have a final position or as an emergency stop button.

Now, my problem is that all the words are spelled correctly but not arranged in any logical sequence.

int button1 = 52 / / button1 - is initialized to pin 52
int button2 = 50 / / button2 - is initialized to pin 50

Semicolons are often a good idea...

ok so:
Button 1 on pin 50 and starts the 150 steps
Button 2 on pin 52 is the stepper motor stop immediately.
Would you have an idea how I have to rewrite my program?

Thank you first for your first answer

Button 2 on pin 52 is the stepper motor stop immediately.

It can't possibly do that, since the motor.step() function does not return until all 150 steps have been performed. Then, you can read the state of the emergency halt switch.

You need to scrap that code. Use the blink without delay example as a model. Determine, on each pass through loop, if the switches are pressed. If the go switch is pressed, and stepping is not happening, set a flag indicating that stepping is necessary.

Then, determine whether it is necessary to step ONCE. That would mean that stepping is required AND that it has been a while since the last step AND that the required number of steps have not been completed. If so, record when, step ONCE, and increment the count of steps taken.

Of course, if the emergency stop switch is pressed, the step flag would be set to false.

I thank you, I have got a question that maybe you could give me a sample code to show or write?