I'm playing around with the Teensy Encoder library here:
It's working great but I'm trying to figure out a clever way to auto detect when only one input is connected (as in a single encoder) instead of a quadrature (with dual inputs). singleCount increments in both input configurations but obviously the position reported by encoder.read() just toggles back and forth between two values when there's only one input connected. Any ideas how to I can detect when there's only one input connected?
GitHub - PaulStoffregen/Encoder: Quadrature Encoder Library for Arduino
Quadrature Encoder Library for Arduino. Contribute to PaulStoffregen/Encoder development by creating an account on GitHub.
github.com
Code:
#include <Encoder.h>
Encoder encoder(A13, 37);
void setup() {
Serial.begin(115200);
Serial.println("Quad/Single Encoder Test:");
}
long prevRead = -999;
uint8_t singleCount;
void loop() {
long newRead;
newRead = encoder.read();
if (newRead != prevRead) {
singleCount++;
Serial.print("\nPosition = ");
Serial.print(newRead);
Serial.print(" single count:");
Serial.print(singleCount);
prevRead = newRead;
}
}
It's working great but I'm trying to figure out a clever way to auto detect when only one input is connected (as in a single encoder) instead of a quadrature (with dual inputs). singleCount increments in both input configurations but obviously the position reported by encoder.read() just toggles back and forth between two values when there's only one input connected. Any ideas how to I can detect when there's only one input connected?