servo-enable

gweimer/servo/servo-enable

Standard servo node with Enable pin added. Detach servo when En is false and allow to free-wheel (or allow other node to control the servo).
servo-enable
@/servo-enable
Standard servo node with Enable pin added. Detach servo when En is false and allow to free-wheel (or allow other node to control the servo).
PORTnumber
Board port number the servo is connected to.
VALnumber
Desired servo angle or value in unit range [0.0, 1.0]. For standard servo 0.0 would be mapped to 0° and 1.0 would be 180°.
Enboolean
Enable servo. Detach servo if this is false.
servo-enable
PORT
VAL
En
To use the node in your project you should have the gweimer/servo 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;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    State* state = getState(ctx);
    auto port = (int)getValue<input_PORT>(ctx);
    auto En = getValue<input_En>(ctx);
 
    if (En) {
        state->servo.attach(port);
        state->servo.write(getValue<input_VAL>(ctx) * 180);
    } else {
        state->servo.detach();
    }
}