peace for everyone.
it is necessary to turn the motor forward and backward, respectively, with the library using the buttons all the way to the limit switch, throw ideas of a simple code with the accelstepper library/ buttons button2pin button3pin are limitswitches
const int button2Pin = 21; const int button3Pin = 22; void setup(){ stepper.setMaxSpeed(50000); stepper.setAcceleration(50000); stepper.setSpeed(50000); if (digitalRead(button1) == LOW && digitalRead(button2) == HIGH){//red button stepper.runToNewPosition(10000); stepper.setCurrentPosition(0); encoder_pos = 0; } if (digitalRead(button1) == HIGH && digitalRead(button2) == LOW){//green button stepper.runToNewPosition(-10000); stepper.setCurrentPosition(0); encoder_pos = 0; }