-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Simple software de-bounce in RotaryEncoder::_encoder_ISR() #4
Comments
My apologies for letting this get cold! So you're proposing the following patch: --- ESP32RotaryEncoder.cpp 2025-01-23 08:49:43
+++ ESP32RotaryEncoder-changed.cpp 2025-01-23 08:56:51
@@ -328,11 +328,14 @@
static int8_t _encoderPosition = 0;
static unsigned long _lastInterruptTime = 0;
static long _stepValue;
-
bool valueChanged = false;
- _previousAB <<=2; // Remember previous state
+ // Simple software de-bounce
+ if( ( micros() - _lastInterruptTime ) < 100 )
+ return;
+ _previousAB <<= 2; // Remember previous state
+
if( digitalRead( encoderPinA ) ) _previousAB |= 0x02; // Add current state of pin A
if( digitalRead( encoderPinB ) ) _previousAB |= 0x01; // Add current state of pin B
\ No newline at end of file
@@ -343,12 +346,12 @@
* Based on how fast the encoder is being turned, we can apply an acceleration factor
*/
- unsigned long speed = millis() - _lastInterruptTime;
+ unsigned long speed = micros() - _lastInterruptTime;
- if( speed > 40 ) // Greater than 40 milliseconds
+ if( speed > 40000 ) // Greater than 40 milliseconds
_stepValue = this->stepValue; // Increase/decrease by 1 x stepValue
- else if( speed > 20 ) // Greater than 20 milliseconds
+ else if( speed > 20000 ) // Greater than 20 milliseconds
_stepValue = ( this->stepValue <= 9 ) ? // Increase/decrease by 3 x stepValue
this->stepValue : ( this->stepValue * 3 ) // But only if stepValue > 9
;
\ No newline at end of file
@@ -384,6 +387,6 @@
_encoderPosition = 0;
// Remember current time so we can calculate speed
- _lastInterruptTime = millis();
+ _lastInterruptTime = micros();
}
}
\ No newline at end of file ...appears to be reasonable enough. I'll commit this change after I've tested. |
I've looked at this closer and done some testing. At first, the changes from But then I noticed something... changing to As for adding the "simple software de-bounce" from the |
Perfectly, thanks for reworking |
Hi, i had a problem with bouncy china knob's
maybe you can update your code like this. I copied from RotaryEncoder::_button_ISR() and changed to micros()
The text was updated successfully, but these errors were encountered: