This question has been asked a couple of times over the years with no answer. I am using the encoder library from the latest teensyduino installation. I am testing with teensy 3.2. I understand from previous "answers" that the default with encoder is to use interrupts. That is not the issue. The problem is that I need to specifically disable interrupts to get any data from the encoder. The very simple sketch below toggles an LED when the encoder count goes above or below 0. It works fine if first line is not commented out but there is no response if it is. I want to be assured that I am not missing encoder counts and it seems that if I disable interrupts this will not be the case. Is there a problem with my choice of pins? All pins on the teensy 3.2 are supposed to be interrupt enabled? What else?
Code:
//#define ENCODER_DO_NOT_USE_INTERRUPTS
#include <Encoder.h>
Encoder readEnc1(5, 6);
long readEncoder_1;
void setup(){
pinMode(13, OUTPUT);
pinMode(5, INPUT_PULLUP); // input encoder
pinMode(6, INPUT_PULLUP); // input encoder
digitalWriteFast(LED_BUILTIN, HIGH); // verify that LED works
}
void loop(){
readEncoder_1 = readEnc1.read();
if (readEncoder_1 < 0) { // backward or clockwise
digitalWriteFast(LED_BUILTIN, HIGH);
}
if (readEncoder_1 > 0){ // forward or clockwise
digitalWriteFast(LED_BUILTIN, LOW);
}
}
Last edited by a moderator: