accelstepper-device

ivanmason/accelstepper/accelstepper-device

Constructor. You can have multiple simultaneous steppers, all moving at different speeds and accelerations, provided you call their run() functions at frequent enough intervals. Current Position is set to 0, target position is set to 0. MaxSpeed and Acceleration default to 1.0.
accelstepper-device
@/accelstepper-device
Constructor. You can have multiple simultaneous steppers, all moving at different speeds and accelerations, provided you call their run() functions at frequent enough intervals. Current Position is set to 0, target position is set to 0. MaxSpeed and Acceleration default to 1.0.
Mtypenumber
1 = Driver 2 = Full 2 Wire 3 = Full 3 Wire 4 = Full 4 wire 6 = Half 3 wire 8 = Half 4 wire
M1port
Arduino digital pin number for motor pin 1. Defaults to pin 2. For a AccelStepper::DRIVER (interface==1), this is the Step input to the driver. Low to high transition means to step)
M2port
Arduino digital pin number for motor pin 2. Defaults to pin 3. For a AccelStepper::DRIVER (interface==1), this is the Direction input the driver. High means forward.
M3port
Arduino digital pin number for motor pin 3. Defaults to pin 4.
M4port
Arduino digital pin number for motor pin 4. Defaults to pin 5.
accelstepper-device
Mtype
M1
M2
M3
M4
DEV
DONE
DONEpulse
DEV@/accelstepper-device
To use the node in your project you should have the ivanmason/accelstepper 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

#pragma XOD require "https://github.com/waspinator/AccelStepper"

// Include C++ library:
{{#global}}
#include <AccelStepper.h>
{{/global}}

struct State {
   uint8_t mem[sizeof(AccelStepper)];
};

using Type = AccelStepper*;

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    // It should be evaluated only once on the first (setup) transaction
    if (!isSettingUp())
        return;

    auto state = getState(ctx);

    const uint8_t port1 = getValue<input_M1>(ctx);
    const uint8_t port2 = getValue<input_M2>(ctx);
    const uint8_t port3 = getValue<input_M3>(ctx);
    const uint8_t port4 = getValue<input_M4>(ctx);

    uint8_t MotorType = getValue<input_Mtype>(ctx);
    Type stepper = new (state->mem) AccelStepper(MotorType, port1, port2, port3, port4);
    
    emitValue<output_DEV>(ctx, stepper);
    emitValue<output_DONE>(ctx, 1);
}