igorantolic / ai-esp32-rotary-encoder

Easy implement rotary encoder to your application using microcontroler like ESP32
GNU General Public License v2.0
284 stars 70 forks source link

When maximum value reached , rotaryEncoder.encoderChanged()) very often give max value, and then , automaticaly max value -1 #39

Closed stpavel closed 1 year ago

stpavel commented 2 years ago

ESP32 board `

define ROTARY_ENCODER_A_PIN 32

define ROTARY_ENCODER_B_PIN 33

define ROTARY_ENCODER_BUTTON_PIN 25

AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, -1, 4);

void setup(){ ... rotaryEncoder.begin(); rotaryEncoder.setup(readEncoderISR); rotaryEncoder.setAcceleration(0); rotaryEncoder.setBoundaries(0, 8, false); rotaryEncoder.setEncoderValue(0); }

void rotary_loop() {

// dont print anything unless value changed if (rotaryEncoder.encoderChanged()) { Serial.println(rotaryEncoder.readEncoder()); } }

void loop(){ rotary_loop(); }

` Now , I rotate encoder only in right , I have got in console: 1 2 3 4 5 6 7 8 7 8 7 8 7 8 7 8 7 8 7 8 7 8 7 So, right after 8 I get 7 but I didn't turn the encoder to the left, I only turn it to the right. And value 7 I have got right after 8, without turn encoder. For example . If I made rotaryEncoder.setBoundaries(0, 9, false); I will got 1 2 3 4 5 6 7 8 9 8 9 8 9 etc. Tell me please , how to fix this bug ?

Frank-Bemelman commented 2 years ago

You could try something like this: rotaryEncoder.setBoundaries(0, 80, false);

And: Serial.println(rotaryEncoder.readEncoder() % 10);