Encoder De-Bouncing

Status
Not open for further replies.

poltergeist

Active member
Hey there, I didn't want to hijack another encoder thread as this is about slightly something else.

I'm using this rotary encoder from sparkfun https://www.sparkfun.com/products/10596
and running the example code for Encoder library. But I'm getting a lot of repeated values if I twist the knob little bit faster (not too fast). I am using Teensy 3 at 96MHz, I thought that would read fast enough the encoders to give an accurate value.
Is there any debounce functionality in the Encoder library? or some sort of average function I could smooth out the readings?

here is the code

Code:
#include <Encoder.h>

Encoder myEnc(10, 9);

void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");
}

long oldPosition  = -999;

void loop() {
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
}

and the results I'm getting

Code:
150
149
150
149
150
151
150
151
152
153
152
153
152
153
154
153
154
153
154
153
154
153
154
153
154
153
154
153
154
153
154
155
156
157
156
157
156
157
156
157
156
157
 
Status
Not open for further replies.
Back
Top