servo-micros

gabbapeople/esc/servo-micros

No description
servo-micros
@/servo-micros
PORTport
Board port number the servo is connected to.
MSECnumber
A microseconds value to write
UPDpulse
Triggers new write
servo-micros
DONE
ERR
PORT
MSEC
UPD
ERRpulse
Fires if write failed. E.g. `PORT` does not exist.
DONEpulse
Fires on writing complete
To use the node in your project you should have the gabbapeople/esc 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

{{#global}}
#include <Servo.h>
{{/global}}

struct State {
    Servo servo;
    int configuredPort = -1;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    if (!isInputDirty<input_UPD>(ctx))
        return;

    State* state = getState(ctx);
    auto port = (int)getValue<input_PORT>(ctx);
    if (!isValidDigitalPort(port)) {
        emitValue<output_ERR>(ctx, 1);
        return;
    }

    if (port != state->configuredPort) {
        state->servo.attach(port);
        state->configuredPort = port;
    }

    state->servo.writeMicroseconds(getValue<input_MSEC>(ctx));
    emitValue<output_DONE>(ctx, 1);
}