encoder

wkov/colony/encoder

No description
encoder
@/encoder
Paport
Encoder port A.
Pbport
Encoder port B.
UPDpulse
Trigger to read encoder state. Important! This node is highly affected by trigger behavior of other nodes.
encoder
Pa
Pb
UPD
BWD
FWD
FWDpulse
Forward pulse.
BWDpulse
Backward pulse.
To use the node in your project you should have the wkov/colony 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 dirtieness disable

node {
    bool prevA = true;
    bool prevB = true;

    void evaluate(Context ctx) {
        bool nextA = ::digitalRead(constant_input_Pa);
        bool nextB = ::digitalRead(constant_input_Pb);

        if ((nextA && nextB) || (prevA && prevB && nextA != nextB)) {
            prevA = nextA;
            prevB = nextB;
        } else if (nextA == prevB && nextB == prevA) {
            if (nextA) {
                emitValue<output_FWD>(ctx, true);
            } else {
                emitValue<output_BWD>(ctx, true);
            }
        }
    }
}