Quadrature encoder with optimized interrupt routines. Encoder will directly define interrupts to minimize overhead. N.B. there is a conflict if any other code in your patch or any libraries you use require attachInterrupt().
encoder-optimized
@/encoder-optimized
Quadrature encoder with optimized interrupt routines. Encoder will directly define interrupts to minimize overhead. N.B. there is a conflict if any other code in your patch or any libraries you use require attachInterrupt().
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.
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"
// User optimized interrupt code
#define ENCODER_OPTIMIZE_INTERRUPTS
//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);
}
}
}