Try this version
#include <AccelStepper.h>
AccelStepper tableSlider(AccelStepper::DRIVER, 5, 6);
const int button = 2; // pin button is on
int val = 0; // current button state
int old_val = 0;
int state = 0;
unsigned long previousMillis = 0;
void setup() {
pinMode(button, INPUT_PULLUP);
tableSlider.setMaxSpeed(1000);
tableSlider.setAcceleration(400);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 100) {
val = digitalRead(button);
if ((val == LOW) && (old_val == HIGH)) {
state = 1;
}
previousMillis = currentMillis;
old_val = val;
}
if (state == 1) {
tableSlider.move(-400);
state = 0;
}
tableSlider.run();
}
...R