I have had trouble with encoders skipping counts and sometimes even stepping in the opposite direction.
I am using a teensy 3.6 with the encoder library 1.4.1
the sketch is the example on the Encoder library page of PJRC.com
this is the typical output from one "click" sometimes it is more and sometimes fewer outputs, and both encoders do the same thing.
is that bad contact bounce? if so is there some way to incorporate a debounce function in to the library or add it after the output?
thanks!
I am using a teensy 3.6 with the encoder library 1.4.1
the sketch is the example on the Encoder library page of PJRC.com
Code:
#include <Encoder.h>
// Change these pin numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder knobLeft(15, 16);
Encoder knobRight(22, 21);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
Serial.println("TwoKnobs Encoder Test:");
}
long positionLeft = -999;
long positionRight = -999;
void loop() {
long newLeft, newRight;
newLeft = knobLeft.read();
newRight = knobRight.read();
if (newLeft != positionLeft || newRight != positionRight) {
Serial.print("Left = ");
Serial.print(newLeft);
Serial.print(", Right = ");
Serial.print(newRight);
Serial.println();
positionLeft = newLeft;
positionRight = newRight;
}
// if a character is sent from the serial monitor,
// reset both back to zero.
if (Serial.available()) {
Serial.read();
Serial.println("Reset both knobs to zero");
knobLeft.write(0);
knobRight.write(0);
}
}
this is the typical output from one "click" sometimes it is more and sometimes fewer outputs, and both encoders do the same thing.
Code:
Reset both knobs to zero
Left = 1, Right = 0
Left = 0, Right = 0
Left = 1, Right = 0
Left = 0, Right = 0
Left = 1, Right = 0
Left = 0, Right = 0
Left = 1, Right = 0
Left = 0, Right = 0
Left = 1, Right = 0
Left = 2, Right = 0
Left = 1, Right = 0
Left = 2, Right = 0
Left = 1, Right = 0
Left = 2, Right = 0
Left = 1, Right = 0
Left = 2, Right = 0
Left = 1, Right = 0
Left = 2, Right = 0
Left = 1, Right = 0
Left = 2, Right = 0
Left = 3, Right = 0
Left = 2, Right = 0
Left = 3, Right = 0
Left = 4, Right = 0
Left = 3, Right = 0
Left = 4, Right = 0
Left = 3, Right = 0
Left = 4, Right = 0
Left = 3, Right = 0
Left = 4, Right = 0
Left = 3, Right = 0
Left = 4, Right = 0
is that bad contact bounce? if so is there some way to incorporate a debounce function in to the library or add it after the output?
thanks!