stepper-28byj48-controller

txgruppi/stepper-28byj48/stepper-28byj48-controller

No description
stepper-28byj48-controller
@/stepper-28byj48-controller
STPpulse
Do a half-step for each pulse
CCWboolean
false to run clockwise and true to run counter-clockwise
DSBpulse
Disable the motor
stepper-28byj48-controller
DONE
OFF
MSK
STP
CCW
DSB
MSKbyte
OFFboolean
true when all wires are off
DONEpulse
Done updating
To use the node in your project you should have the txgruppi/stepper-28byj48 library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State {
    int index = 0;
};

{{ GENERATED_CODE }}

uint8_t positions[8] = {
    0b00001000,
    0b00001100,
    0b00000100,
    0b00000110,
    0b00000010,
    0b00000011,
    0b00000001,
    0b00001001,
};

void emitAll(Context ctx, uint8_t pins, int index, bool off) {
    emitValue<output_MSK>(ctx, pins);
    emitValue<output_OFF>(ctx, off);
    emitValue<output_DONE>(ctx, 1);
}

void evaluate(Context ctx) {
    State* state = getState(ctx);

    if (isInputDirty<input_DSB>(ctx)) {
        return emitAll(ctx, 0, state->index, true);
    }
    if (!isInputDirty<input_STP>(ctx)) {
        return;
    }

    bool ccw = getValue<input_CCW>(ctx);

    if (ccw) {
        state->index -= 1;
    } else {
        state->index += 1;
    }

    if (state->index < 0) {
        state->index = 7;
    } else if (state->index > 7) {
        state->index = 0;
    }

    emitAll(ctx, positions[state->index], state->index, false);
}