-> Please find German version below <-
Greetings community,
this problem is driving me nuts: I have a sketch with an ESP32-wroom-32 and a rotary encoder KY-040. An interrupt is being triggerd by the encoder switch (PIN) and calls the ISR ok. My problem is that the interrupt ISR is also being called if I rotate the encoder knob.
This is my sketch:
#include <ESP32Encoder.h>
#define ENCODER_A 34 // CLK
#define ENCODER_B 32 // DT
#define ENCODER_BTN 14 // SW
unsigned int btnEncTime = 0;
unsigned int last_btnEncTime = 0;
unsigned int counter = 0;
// =====================================================================
// Interrupt Functions
//
void IRAM_ATTR intENCBTN() {
btnEncTime = millis();
if (btnEncTime - last_btnEncTime > 250)
{
counter++;
Serial.print("BTN ENC pressed - Counter: ");
Serial.println(counter);
last_btnEncTime = btnEncTime;
}
}
void setup() {
Serial.begin(115200);
pinMode(ENCODER_BTN, INPUT_PULLUP); // SWITCH ENC1 mit internal pullup
attachInterrupt(ENCODER_BTN, intENCBTN, FALLING); // if SWITCH ENC1 goes from HIGH to LOW
}
void loop() {
// put your main code here, to run repeatedly:
}
And here the output of the serial monitor:
I pressed the encoder switch 3 times only, but rotated the encoder knob inbetween. As you can see, this also triggers the ISR function.
Please help me to find my mistake.
Many thanks for your help.
Fliegerhans65
// =======================================================================
// German version
// =======================================================================
Hallo Zusammen,
folgendes Problem treibt mich gerade in den Wahnsinn: Ich habe einen Sketch mit einem ESP32-wroom-32 und einem Rotary Encoder KY-040. Ich habe einen Interrupt auf den Encoder Switch (PIN) gelegt und die ISR löst auch sauber aus. Mein Problem ist das die ISR aber auch durch Drehen des Encoders ausgelöst wird.
Hier der Sketch:
#include <ESP32Encoder.h>
#define ENCODER_A 34 // CLK
#define ENCODER_B 32 // DT
#define ENCODER_BTN 14 // SW
unsigned int btnEncTime = 0;
unsigned int last_btnEncTime = 0;
unsigned int counter = 0;
// =====================================================================
// Interrupt Functions
//
void IRAM_ATTR intENCBTN() {
btnEncTime = millis();
if (btnEncTime - last_btnEncTime > 250)
{
counter++;
Serial.print("BTN ENC pressed - Counter: ");
Serial.println(counter);
last_btnEncTime = btnEncTime;
}
}
void setup() {
Serial.begin(115200);
pinMode(ENCODER_BTN, INPUT_PULLUP); // SWITCH ENC1 mit internal pullup
attachInterrupt(ENCODER_BTN, intENCBTN, FALLING); // if SWITCH ENC1 goes from HIGH to LOW
}
void loop() {
// put your main code here, to run repeatedly:
}
Hier die Ausgabe des Serial Monitors:
Dabei habe ich den Switch 3x gedrückt, aber den Encoder dazwischen ständig gedreht.
Was mache ich falsch?
Vielen Dank für Eure Hilfe, daß ist mein erster Post.
Fliegerhans65
