l9110-h-bridge

cesars/motor/l9110-h-bridge

No description
l9110-h-bridge
@/l9110-h-bridge
1Aport
Board port to write to
1Bport
Board port to write to
FORWboolean
BACKWboolean
ACTpulse
Triggers new write
l9110-h-bridge
1A
1B
FORW
BACKW
ACT
DONE
DONEpulse
Fires on writing complete
To use the node in your project you should have the cesars/motor 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 error_raise enable

struct State {
};

{{ GENERATED_CODE }}

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

    const uint8_t port1 = getValue<input_1A>(ctx);
    const uint8_t port2 = getValue<input_1B>(ctx);
    if (!isValidDigitalPort(port1) || !isValidDigitalPort(port2)) {
        raiseError<output_DONE>(ctx);
        return;
    }

    ::pinMode(port1, OUTPUT);
    ::pinMode(port2, OUTPUT);
    const bool val1 = getValue<input_FORW>(ctx);
    const bool val2 = getValue<input_BACKW>(ctx);
    if (val1 > val2){
       ::digitalWrite(port1, 1);
       ::digitalWrite(port2, 0);
    }else if(val1 < val2){
       ::digitalWrite(port1, 0);
       ::digitalWrite(port2, 1);
    }else{
       ::digitalWrite(port1, 0);
       ::digitalWrite(port2, 0);
    }
    emitValue<output_DONE>(ctx, 1);

}