Variation in rotary encoders

Hi,
Several years back I purchased a rotary encoder from somewhere and have periodically used it in breadboarded projects. It's been in and out of breadboard so many times its pins have broken off. So I bought a bunch of rotary encoders from Ebay a while back, thinking that they were all pretty much the same. How very wrong I was!

I just discovered that the newer encoders I bought increment 3 (sometimes 4) times versus the old one's single increment.
I am trying to use one in a project in which I am following this tutorial:

I have tried changing values in the relevant method: readRotaryEncoder() , as well as the header and cpp files without any success (I managed to make the number of increments larger, but not smaller), however I am not an accomplished enough programmer to be able to make it work with the new rotary encoder.

Can anyone suggest how I might achieve this?

I have attached the header and cpp files and here is the readRotaryEncoder method:

void readRotaryEncoder()
{
 value += encoder->getValue();
  
  if (value/2 > last) {
    last = value/2;
    down = true;
    delay(150);
  }else   if (value/2 < last) {
    last = value/2;
    up = true;
    delay(150);
  }
}

ClickEncoder.cpp (5.81 KB)

ClickEncoder.h (2.68 KB)

Nokia5110MenuRotary_CHANGING_v1_1.ino (18.2 KB)

I forgot to add that I have tried the constructor in ClickEncoder.h

ClickEncoder(uint8_t A, uint8_t B, uint8_t BTN = -1, 
               uint8_t stepsPerNotch = 1, bool active = LOW);

However, regardless of the number I put in for stepsPerNotch, it makes no difference to the operation. Although when I use that constructor instead of the default one

ClickEncoder encoder = new ClickEncoder(A1, A0, A2);

then the pushbutton (A2) stops working.

There is only one constructor surely? Which version of ClickEncoder library?

You failed to post your entire sketch so we can't see what you did with the constructor call...

MarkT:
There is only one constructor surely? Which version of ClickEncoder library?

The version of ClickEncoder used is the one linked to in the tutorial here:

Correct, there was only one constructor in the ClickEncoder.h and ClickEncoder.cpp header files ,however it had 5 fields:

ClickEncoder::ClickEncoder(uint8_t A, uint8_t B, uint8_t BTN, uint8_t stepsPerNotch, bool active)

while the constructor used in the tutorial used only 3 fields:

ClickEncoder *encoder;
encoder = new ClickEncoder(A1, A0, A2);

so it rather baffled me how it worked without throwing compilation errors...

You failed to post your entire sketch so we can't see what you did with the constructor call...

I didn't attach my full code as it was quite long (~700 lines of code}
I have now attached my full code to the first post in this thread, so you can take a look.

I would recommend that you use the library example for the click encoder library with Serial output to work out your issues with the Constructor.

In C++ arguments with defaults are optional:

Here's some explanation of the constructor.

This is the definition from the .h file which shows the defaults

 ClickEncoder(uint8_t A, uint8_t B, uint8_t BTN = -1, 
               uint8_t stepsPerNotch = 1, bool active = LOW);

// this is the constructor I tried using based on the constructor in ClickEncoder.h (above),
// the clicks were the same but the button stopped working
//encoder = new ClickEncoder(A1, A0, A2, 8, true);

Now look at the implementation of the constructor in the .cpp file

ClickEncoder::ClickEncoder(uint8_t A, uint8_t B, uint8_t BTN, uint8_t stepsPerNotch, bool active)
  : doubleClickEnabled(true), accelerationEnabled(true),
    delta(0), last(0), acceleration(0),
    button(Open), steps(stepsPerNotch),
    pinA(A), pinB(B), pinBTN(BTN), pinsActive(active)
{
  uint8_t configType = (pinsActive == LOW) ? INPUT_PULLUP : INPUT;
  pinMode(pinA, configType);
  pinMode(pinB, configType);
  pinMode(pinBTN, configType);
  
  if (digitalRead(pinA) == pinsActive) {
    last = 3;
  }

  if (digitalRead(pinB) == pinsActive) {
    last ^=1;
  }
}

You can see that the pinsActive(active) is used to set the pinMode to either INPUT or INPUT_PULLUP., and the default is active LOW with the pinMode INPUT_PULLUP.

When you set active = true it was the same as saying active = HIGH. If the push button is indeed working properly with the constructor which is using the default LOW, then the button reading will not be working properly when you told the library it is wired as active HIGH.

The steps per notch value should be either 1,2, or 4. Using 8 makes no sense.