Forum Rule: Always post complete source code & details to reproduce any issue!
-
Teensyduino encoder library "provides 4X counting mode" ?
Hi, I am using an encoder and the values returned are skipping by 4 (each detent increments the value by 4). I understand this is because the encoder has quadrature output, however, the Teensyduino encoder library "provides 4X counting mode" correct? How do I engage the 4x counting mode?
My circuit is on a pcb with the bourns recomended circuit so I am confident this is a software question. I could divide by 4, but I want to use the library functionality if it it is available.
Bourns Encoder Cat. No. PEC12R-2225F-N0024
Teensy LC
Code:
#include <Encoder.h>
Encoder knobLeft(12, 22);
void setup() {
Serial.begin(9600);
Serial.println("Encoder Test:");
}
long positionLeft = -999;
void loop() {
long newLeft;
newLeft = knobLeft.read();
if (newLeft != positionLeft) {
Serial.print("Left = ");
Serial.print(newLeft);
Serial.println();
positionLeft = newLeft; }
if (Serial.available()) {
Serial.read();
Serial.println("Reset both knobs to zero");
knobLeft.write(0);
}
}
-
For another take on managing encoders look here:-
https://github.com/luni64/EncoderTool
-
Thank you MatrixRat. I will try implementing the EncoderTool library from luni64.
I added my schematic - maybe I executed the example from Bourns incorrectly.
-
Senior Member

Originally Posted by
mikemontauk
How do I engage the 4x counting mode?
The encoder library is, by design, operating in 4x counting mode: "The library updates its count at each change, which is often called 4X counting". It's not a mode you can select.
I just divide by 4 to count the detents.
Paul
-
Thank you for clarifying Paul. I will divide by 4.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules