encoder

wayland/encoder/encoder

Quadrature encoder.
encoder
@/encoder
Quadrature encoder.
P1port
Port for signal one. Use a hardware interrupt pin for best performance.
P2port
Port for signal 2. Use a hardware interrupt pin for best performance.
Readpulse
A pulse to this input triggers a read of position.
encoder
P1
P2
Read
Pos
Done
Donepulse
Pulse on read.
Posnumber
Position.
To use the node in your project you should have the wayland/encoder 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

// Tell XOD where it could download the library:
#pragma XOD require "https://github.com/PaulStoffregen/Encoder"

//Include C++ libraries
#include <Encoder.h>

node {
    meta {
        // Define our custom type as a pointer on the class instance.
        using Type = Encoder*;
    }
    
    static_assert(isValidDigitalPort(constant_input_P1), "must be a valid digital port");
    static_assert(isValidDigitalPort(constant_input_P2), "must be a valid digitial port");

    Encoder enc = Encoder(constant_input_P1, constant_input_P2);

    void evaluate(Context ctx) {

        if (isInputDirty<input_Read>(ctx)) {
            emitValue<output_Pos>(ctx, enc.read());
            emitValue<output_Done>(ctx, 1);
        }
    }
}