Answer the question
In order to leave comments, you need to log in
How to make a certain number of steps with a stepper per second?
I have two steppers, I use the accelStepper library, I need the steppers to move 300 steps, wait for example 3 seconds and move 300 steps again, the closest that I managed to do this, but after a while the int overflows and everything stops working.
I know that there is a setCurrentPosition method and you can set it to zero in each cycle, and then ask to take steps to point 200 and so on again, but if I set the point as zero at the end of the cycle, everything also stops working, so I use a strange addition please tell me how to do it right
AccelStepper stepper1; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper2(AccelStepper::FULL4WIRE, 6, 7, 8, 9);
int position = 0;
int last_time = 0;
void setup()
{
stepper1.setMaxSpeed(300.0);
stepper1.setAcceleration(100.0);
stepper2.setMaxSpeed(300.0);
stepper2.setAcceleration(100.0);
last_time = millis();
}
void loop() {
position = position+300;
stepper1.moveTo(position);
stepper2.moveTo(position);
stepper1.run();
stepper2.run();
if (millis() - last_time >= 3000) {
stepper1.stop();
delay(1000);
last_time = millis(); // сброс таймера
}
}
Answer the question
In order to leave comments, you need to log in
setMaxSpeed - this is "a certain number of steps per second", i.e. speed
A instead
stepper1.moveTo(position);
in your case it is better to use
stepper1.move (300);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question