jjzai123
Junior Member level 3
I'm trying to code my motor working like this:
1. Let's said the target is 2048
2. I programmed the motor to move 200 steps until it reach 2048
The questions is how to set the current moved steps to current position?
My questions is like when first the motor moved 200 steps, the current position will set to 200, check if there is still steps left the motor will move again 200 and set the current position to 200+200 something like this.
1. Let's said the target is 2048
2. I programmed the motor to move 200 steps until it reach 2048
The questions is how to set the current moved steps to current position?
Code:
#include <AccelStepper.h>
#include <MultiStepper.h>
#define blue 8
#define pink 9
#define yellow 10
#define orange 11
AccelStepper stepper(AccelStepper::HALF4WIRE, orange, pink, yellow, blue);
int target = 2048;
int current_pos = 0;
int steps_left;
void setup()
{
Serial.begin(9600);
stepper.setMaxSpeed(1200);
stepper.setSpeed(200);
stepper.setAcceleration(110);
}
void loop()
{
target = stepper.targetPosition();
current_pos = stepper.currentPosition();
steps_left = stepper.distanceToGo();
steps_left = target - current_pos;
if(steps_left != 0)
{
//the code here is supposed to be run to 200 steps without blocking and
after it done, update the current position till it reach 2048 steps
stepper.runToNewPosition(200);
delay(1000);
}
}
My questions is like when first the motor moved 200 steps, the current position will set to 200, check if there is still steps left the motor will move again 200 and set the current position to 200+200 something like this.