Hi guys,
This is my first time posting here. I currently have a project where we need to make a profile for a stepper motor with accel, constant speed, decel, and a delay.
After some research, i found that the accelstepper library has the acceleration and deceleration function.
Below is the profile that i am required to make.

Below is the code i used
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::FULL4WIRE, 8, 9, 10, 11);
//no of step to move to achieve 40step aka 20ms
void setup()
{
//setup accel speed 20steps/sec,accel: 5steps/sec. Accel/decel should be 4s (20/5)
stepper.setMaxSpeed(20);
stepper.setAcceleration(5);
}
void loop()
{
if (stepper.distanceToGo() == 0)
{
//delay 3s here for the idle
delay(3000);
// set the distance to move 120steps = 80steps for accel+decel, 40steps constant speed. 40steps = 2 secs.
stepper.move(120);
}
stepper.run();
}
The distance is calculated with D=V*V/2A *V= max speed, A=Acceleration.
From the code, one cycle should be around 10second (exclude idle). When i try to use a stop watch, it is around 9+ seconds.
i am using LED to check the timing of the profile now
I would like to know if i am coding it correctly? or the stop watch was not timed properly?