How many steps is 180 degrees on your motor?
Which motor driver are you using?
How fast is the first sweep (0 to 180 in seconds? The second sweep (180 to 0)?
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
void setup()
{
// Change these to suit your stepper if you want
stepper.setMaxSpeed(100);
stepper.setAcceleration(50);
}
void loop()
{
static unsigned long lastTime = 0
if (millis() - lastTime >= 10000) // every 10 seconds
{
lastTime = millis();
stepper.setSpeed(100); // 100 steps per second
stepper.runToPosition(100); // 1/2 turn
stepper.setSpeed(20);
stepper.runToPosition(0); //back to beginning.
}
}
Dear johnwasser,
sorry for the late reply. The code you proposed is exactly what I am looking for (if I understood correctly). So, with this code, I can change the parameters in order to change the acceleration, speed, and number of steps. Perfect.
Big big thanks, and I whish you a nice weekend...
Also, following your posts in the future
Dear JCA34F,
sorry for the late reply. Actually, it seems the code that @johnwasser proposed is exactly what I am looking for....what I need is actually option to control (and adjust) acceleration, speed, and number of steps of the stepper motor, when moving forward for 180 degrees, than stop, and going backwards again for 180 degrees.
Thanks a lot for advice, and I thing that the topic is also interesting for all of us....
Kind regards,
Dear gilshultz,
sorry for the late reply. Actually, it seems the code that @johnwasser proposed is exactly what I am looking for....what I need is actually option to control (and adjust) acceleration, speed, and number of steps of the stepper motor, when moving forward for 180 degrees, than stop, and going backwards again for 180 degrees.
Thanks a lot for advice, and I thing that the topic is also interesting for all of us....
Kind regards,
Dear jremington,
sorry for the late reply. Actually, it seems the code that @johnwasser proposed is exactly what I am looking for....what I need is actually option to control (and adjust) acceleration, speed, and number of steps of the stepper motor, when moving forward for 180 degrees, than stop, and going backwards again for 180 degrees.
Thanks a lot for advice, and I thing that the topic is also interesting for all of us....
Kind regards,
Dear paulpaulson,
sorry for the late reply. Actually, it seems the code that @johnwasser proposed is exactly what I am looking for....what I need is actually option to control (and adjust) acceleration, speed, and number of steps of the stepper motor, when moving forward for 180 degrees, than stop, and going backwards again for 180 degrees.
Thanks a lot for advice, and I thing that the topic is also interesting for all of us....
Kind regards,