Getting States


Getting Operation States

You can get the operation state by using getState() function.

state = step.getState()

This function returns the operation state of a stepper motor.
Returned values are as follows:

value state
0 stopped
1 control locked
otherwise running

Example

#include <PhpocExpansion.h>
#include <Phpoc.h>

byte spcId = 1;

ExpansionStepper step(spcId);

int state;

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(800);

    step.stepGoto(400);

    while(state = step.getState()) {
        Serial.print("state: ");
        Serial.println(state);
        delay(200);
    }

    Serial.print("state: ");
    Serial.println(state);
}

void loop() {

}
state: 2
state: 2
state: 2
state: 2
state: 2
state: 2
state: 2
state: 0

Getting a Counter Position

You can get a counter position by using getPosition() function.

pos = step.getPosition()

This function returns the current counter position of a stepper motor.

Example

#include <PhpocExpansion.h>
#include <Phpoc.h>

byte spcId = 1;

ExpansionStepper step(spcId);

int pos = -400;

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(800);
    step.setPosition(pos);

    step.stepGoto(400);

    while(step.getState()) {
        pos = step.getPosition();
        Serial.print("position: ");
        Serial.println(pos);
        delay(200);
    }
}

void loop() {

}
position: -400
position: -369
position: -302
position: -214
position: -126
position: -39
position: 48
position: 135
position: 223
position: 310
position: 375
position: 400

Getting States of Digital Input Ports

You can get states of digital input ports by using getEio() function.

state = step.getEio(id)

The returned states are as follows:

returned value state
0 LOW
1 HIGH (default)

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());
}

void loop() {
    Serial.print(step.getEio(0));
    Serial.print(step.getEio(1));
    Serial.print(step.getEio(2));
    Serial.print(step.getEio(3));
    Serial.println();
    delay(1000);
}
1111  
1111  
1110  
0110  
...