Hi all,
I have connected a rotary encoder to a Teensy 3.2 by means of digital pin 0 for the switch (switching to ground) and digital pins 1 and 2 to the rotating parts.
I am using the Encoder library and I based my code on the example code on the relevant page:
The problem is that one a turn to either side, the volume of registered values is not equal: sometimes I get one value, then three, then two. I need the encoder to reliably just register one change at the time, so the rest of the code triggers reliably. The only way I managed to do this, was to add a long delay (250 ms and up). As I am also updating a TFT screen in the "loop" part, this delay is not acceptable.
Can anyone give me a hint on how to get this working? I was thinking about a time based buffer, but that would also hold up the execution of the program.
Cheers all,
BC
I have connected a rotary encoder to a Teensy 3.2 by means of digital pin 0 for the switch (switching to ground) and digital pins 1 and 2 to the rotating parts.
I am using the Encoder library and I based my code on the example code on the relevant page:
Code:
//Rotary encoder
long Value2Knob1 = Knob1.read();
delay(250);
if (Value2Knob1 != Value1Knob1) {
//Serial.print("Knob1: ");
//Serial.println(Value2Knob1);
if ( Value2Knob1 < Value1Knob1 ) {
Serial.println("---");
Index1 = Index1 - 1;
if ( Index1 <= -1 ) {
Index1 = 11;
}
}
if ( Value2Knob1 > Value1Knob1 ) {
Serial.println("+++");
Index1 = Index1 + 1;
if ( Index1 >= 12 ) {
Index1 = 0;
}
}
The problem is that one a turn to either side, the volume of registered values is not equal: sometimes I get one value, then three, then two. I need the encoder to reliably just register one change at the time, so the rest of the code triggers reliably. The only way I managed to do this, was to add a long delay (250 ms and up). As I am also updating a TFT screen in the "loop" part, this delay is not acceptable.
Can anyone give me a hint on how to get this working? I was thinking about a time based buffer, but that would also hold up the execution of the program.
Cheers all,
BC
Last edited: