Got rid of encoder library, rewrote encoder handling to use Pin Change Interrupts

This commit is contained in:
Oleksiy
2025-04-05 19:34:08 +03:00
parent fb86269b21
commit 395fa1ef1f
2 changed files with 88 additions and 16 deletions

View File

@ -87,24 +87,30 @@ void checkInputs() {
updateScreen();
}
//encoder
encoder.tick();
int encPosition = encoder.getPosition();
int encDirection = (int)(encoder.getDirection());
if (encPositionOld != encPosition) {
int change = encPositionOld - encPosition;
if (reverseEnc) {
//encoder
// things to try:
// 1 - make checkInputs one if-else chain and move the encoder part to the first condition
// 2 - count "burst" changes and apply acceleration
// 3 - pinchange interrupts? https://github.com/mathertel/RotaryEncoder/blob/master/examples/InterruptRotator/InterruptRotator.ino
//encoder.tick();
//int encPosition = 0;//encoder.getPosition();
//int8_t encDirection = 0;//(int)(encoder.getDirection());
if (encoderChange != 0) {
int change = encoderChange;
if (!reverseEnc) {
change = change * -1;
}
unsigned long ms = encoder.getMillisBetweenRotations();
/*if (encDirectionOld == encDirection && ms < 20) { //encoder acceleration
/*unsigned long ms = 0;//encoder.getMillisBetweenRotations();
if (encDirectionOld == encDirection && ms < 18) { //encoder acceleration
change = change * 5;
} else if (encDirectionOld == encDirection && ms < 80) {
} /* else if (encDirectionOld == encDirection && ms < 80) {
change = change * 2;
} else */ if (encDirectionOld != encDirection && ms < 200) { //filter out encoder "jumps"
} else */
if (((encoderChange > 0) != encoderDirectionOld) && encoderTimeBetweenPulses < 200) { //filter out encoder "jumps"
change = 0;
}
encDirectionOld = encDirection;
encoderDirectionOld = (encoderChange > 0);
if (displayScreen == 0) {
byte channelCV;
if (!insideTab && !shiftBtnPushed) { //Change tab
@ -364,7 +370,8 @@ void checkInputs() {
}
updateScreen();
encPositionOld = encPosition;
//encPositionOld = encPosition;
encoderChange = 0;
}
//play button