buttonWasPressed = true;
motor.move(10000); //Set target (relative position)
}
else if (digitalRead(downpin) == HIGH) { // check if the input is HIGH (button pushed)
buttonWasPressed = true;
motor.move(-10000); //Set target (absolute position)
}
else if (buttonWasPressed)
{
// button was pressed, but isn't now! Lets halt!!
motor.setSpeed(0);
motor.moveTo(motor.currentPosition);
// an alternative is motor.stop() that will smoothly decelerate to a halt.
}
motor.run(); // will only step if required
Serial.println(motor.currentPosition());
}
Though note that Serial.println(...) will slow your motors down a lot. The .move(10000) assumes that 10000 steps is enough to get to top speed, but not enough to start decelerating.
I haven't tested the above. You might choose to use a buttons library for debouncing your buttons.
--
sn