You can control a stepper motor relative to the current position, not the initial position by using stepMove() function. This function can be executed only when the motor is NOT running.
step.stepMove(step)
step.stepMove(step, speed)
step.stepMove(step, speed, accel)
step - the target counter position
You can define the forward or reverse rotation by adding "+" or "-" in front of the pos value. (default : "+") The target counter position is relative to the current position, not the initial position.
speed - rotation speed in pps unit
※ pps: pulse per second
accel - acceleration in pps/s unit
The deceleration is applied with the same value with the acceleration.
#include <PhpocExpansion.h>
#include <Phpoc.h>
byte spcId = 1;
ExpansionStepper step(spcId);
void setup() {
Serial.begin(9600);
while(!Serial)
;
Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
Expansion.begin();
Serial.println(step.getPID());
Serial.println(step.getName());
step.setMode(4);
step.setVrefStop(2);
step.setVrefDrive(8);
step.setResonance(120, 250);
step.setSpeed(400);
step.setAccel(0, 0);
step.setPosition(0);
step.stepMove(400);
delay(2000);
step.stepMove(-400);
delay(2000);
step.stepMove(400);
delay(2000);
while(step.getState()) {
delay(1);
}
}
void loop() {
}