This function controls a stepper motor based on the initial position, not the current counter position. This function can be used even when the motor is running.
step.stepGoto(pos)
step.stepGoto(pos, speed)
step.stepGoto(pos, speed, accel)
pos - a integer value which represents a target position (-1 billion ~ +1 billion)
speed - a integer value which represents the rotating speed in pps unit (~ 240000)
accel - a integer value which represents the deceleration speed in pps/s unit (~ 2400000)
※ pps: pulse per second
none
#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.stepGoto(400);
delay(2000);
step.stepGoto(-400);
delay(2000);
step.stepGoto(400);
delay(2000);
while(step.getState()) {
delay(1);
}
}
void loop() {
}