Sorry, I forgot to put the code...
Here it is, after the homing process, the steppers starts moving and stops when the button is pressed. I need to move the stepper X number of steps when the button is pressed and then stop to wait the next button press.
#include <AccelStepper.h>
AccelStepper stepper (1, 9 ,8);
#define home_switch 4
#define buttonState 7
long initial_homing=-1;
long stepstogo=16;
void setup()
{
pinMode(home_switch, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
delay(5);
stepper.setMaxSpeed(100);
stepper.setAcceleration(100);
while (digitalRead(home_switch)) {
stepper.moveTo(initial_homing);
initial_homing--;
stepper.run();
delay(5);
}
stepper.setCurrentPosition(0);
stepper.setMaxSpeed(500000);
stepper.setAcceleration(5000);
stepper.setSpeed(2800);
}
void loop()
{
if (digitalRead(buttonState)){
stepper.move(16);
}
stepper.run();
}