#include <Encoder.h> // https://www.pjrc.com/teensy/td_libs_Encoder.html
struct ExtendedCoder {
Encoder encoder;
const char * name;
long oldPosition;
long position;
long multiplier;
bool changed() {
position = encoder.read() >> 2; // 4 ticks par click on divise par 4
if (oldPosition != position) {
oldPosition = position;
return true;
}
return false;
}
};
ExtendedCoder extendedEncoders[] = {
{{ 3, 2}, "encoder10", -1, 0, 10},
{{ 7, 6}, "encoder100", -1, 0, 100},
{{11, 10}, "encoder1000", -1, 0, 1000},
};
void setup() {
Serial.begin(115200);
}
void loop() {
for (auto& ec : extendedEncoders)
if (ec.changed()) {
Serial.print(ec.name);
Serial.print("\t");
Serial.println(ec.position * ec.multiplier);
}
}