I am trying to get a rotary encoder working on a Teensy 3.2 and 3.6 - I have tried my code on both but the same happens.
I am getting a count of 4 for each detent on a Bournes 24 position rotary encoder.
My code:
The output I see on the serial monitor - 2 clicks right and two clicks left:
Each click results in 4 lines being printed to the serial monitor.
Circuit is below - only difference is that I am using a HC7414N Schmitt trigger (yes its decoupled !):
If I turn the rotary encoder EXTREMELY slowly between detents I can get it to count up / down in 1 increment.
Any help would be appreciated ! Is it the type of encoder I have that is doing this ? 4 counts per detent ?
I am getting a count of 4 for each detent on a Bournes 24 position rotary encoder.
My code:
Code:
#define ENCODER_OPTIMIZE_INTERRUPTS
#include <Encoder.h>
Encoder encoder0(2, 3);
long encoderPos = -999;
void setup() {
Serial.begin(9600);
Serial.println("Encoder Test:");
}
void loop() {
long newEncoderPos;
newEncoderPos = encoder0.read();
if (newEncoderPos != encoderPos) {
Serial.print("Position = ");
Serial.print(newEncoderPos);
Serial.println();
encoderPos = newEncoderPos;
}
}
The output I see on the serial monitor - 2 clicks right and two clicks left:
Code:
Encoder Test:
Position = 0
Position = 1
Position = 2
Position = 3
Position = 4
Position = 5
Position = 6
Position = 7
Position = 8
Position = 7
Position = 6
Position = 5
Position = 4
Position = 3
Position = 2
Position = 1
Position = 0
Each click results in 4 lines being printed to the serial monitor.
Circuit is below - only difference is that I am using a HC7414N Schmitt trigger (yes its decoupled !):
If I turn the rotary encoder EXTREMELY slowly between detents I can get it to count up / down in 1 increment.
Any help would be appreciated ! Is it the type of encoder I have that is doing this ? 4 counts per detent ?