Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Resetting encoder values

  1. #1

    Resetting encoder values

    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.

  2. #2
    Senior Member
    Join Date
    Aug 2018
    Location
    Brisbane, Australia
    Posts
    139
    You probably need to call encoderknob.write(newencoderposition) whenever you reset the value

  3. #3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •