stepGotoSW()


Description

This function controls a stepper motor until a limit switch is closed.

Syntax

step.stepGotoSW(id, dir)
step.stepGotoSW(id, dir, speed)
step.stepGotoSW(id, dir, speed, accel)

Parameters

id - a integer value which represents the port number of a limit switch (0 ~ 3)
dir - a integer value which represents the direction of rotation

dir description
0 or grater than 0 forward
otherwise reverse

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

Returns

none

Example

#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.setVrefDrive(8);
    step.setSpeed(400);
    step.setAccel(0);

    // rotate until digital input 0 is LOW
    Serial.print("find positive limit ...");
    step.stepGotoSW(0, 1);
    while(step.getState()) {
        delay(1);
    }
    Serial.println("done");

    delay(1000);

    // rotate until digital input 1 is LOW
    Serial.print("find negative limit ...");
    step.stepGotoSW(1, -1);
    while(step.getState()) {
        delay(1);
    }
    Serial.println("done");
}

void loop() {

}