Resetting encoder values

SteveCS

Well-known member
Hi

I am using the encoder libary and need to limit it's range. Basically, I am using the encoder value to navigate a menu.

Code:
do {

    encoderbutton.update();

    newencoderposition = encoderknob.read();

    if (newencoderposition != encoderposition) {

      if (newencoderposition >12) {
        newencoderposition = 0;
      }
      if (newencoderposition <0) {
        newencoderposition = 12;
      }
      Serial.print("Encoder = ");
      Serial.println(newencoderposition);
      encoderposition = newencoderposition;
      
      menuitems();

      if (encoderbutton.changed() ) {                                                   // Encoder button
        int deboucedInput = encoderbutton.read();
        if (deboucedInput == LOW ) {
          selectitem();
        }
      }
    }

  } while (exitmenu == false);
  exitmenu = false;

But this code just limits it to 0-12, it doesn't roll over as I expected (>12 starts at 0 and <0 returns to 12).
Does the encoder library store the value internally or something?

Currently, this just stops at zero or 12, no roll-over.
 
That was it. Thank you

Why oh why isn't that in the keywords txt file or mentioned anywhere. It does my head in when people design this stuff and miss out important information.
We are not all tech wizards.

Thanks again
 
Back
Top