I am trying to create a program where the stepper motor controlled with a L298H stops when hitting a limitswitch. However with the default stepper.h it needs to finish its pre-set length.
I am wondering if theres a library or code that helps to keep the motor running until it hits the limit switch.
You could use the MoToStepper class of my MobaTools Lib. This lib is not blocking while the motor turns. You can read your limit switch and stop at any time.The lib can be installed by means of the library manager. Examples and a documentation in english are provided.
Thanks for your reply! i tried the library you created. However the motor only vibrates and doesnt spin. The code is used is this one:
/* ====== minimumStepper =======================================
* Bare minimum to get a stepper with step/dir driver turning
*/
#include <MobaTools.h>
// Stepper connections - Please adapt to your own needs.
const int stepsPerRev = 200; // Steps per revolution - may need to be adjusted
MoToStepper stepper1( stepsPerRev, STEPDIR ); // create a stepper instance
void setup() {
stepper1.attach(8,9,10,11);
stepper1.setSpeed( 300 ); // 30 rev/min (if stepsPerRev is set correctly)
stepper1.setRampLen( stepsPerRev / 2); // Ramp length is 1/2 revolution
stepper1.rotate(1); // start turning, 1=vorward, -1=backwards
}
void loop() {
}