Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotary button #1

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Rotary button #1

wants to merge 11 commits into from

Conversation

darkworks
Copy link

@darkworks darkworks commented Nov 8, 2019

rotary button if checks seems wrong

 unsigned char result_btn = r.process_button();
  if (result == BTN_NONE) {
    // do nothing
  }
  else if (result == BTN_PRESSED) {
    Serial.println("Button pressed");
  }
  else if (result == BTN_RELEASED) {
    Serial.println("Button released");
  }

i think it should be like

  unsigned char result_btn = r.process_button();
  if (result_btn == BTN_NONE) {
    // do nothing
  }
  else if (result_btn == BTN_PRESSED) {
    Serial.println("Button pressed");
  }
  else if (result_btn == BTN_RELEASED) {
    Serial.println("Button released");
  }
  • i tested your rotary_button branch its not smooth when pressing buttons and releasing it , sometime it return multiple press , i manage to fix it in bad way from your earlier commits , LOL

this one is smooth

unsigned char Rotary::process_button() {
  // Grab button state
  unsigned char pinstate = digitalRead(pin3);
  unsigned char btnstate = BTN_NONE;
  if (pinstate == HIGH && state_btn == LOW) {
      btnstate = BTN_RELEASED;
	  state_btn = HIGH;
  }
  if (pinstate == LOW && state_btn == HIGH) {
      btnstate = BTN_PRESSED;
	  state_btn = LOW;
  }
  return btnstate;
}

@sh123
Copy link
Owner

sh123 commented Nov 8, 2019

Seems to be bug in example. It would be easier to add button support into original author's repo at https://github.com/brianlow/Rotary, I just quickly needed both click and long click for my homebrew project to support more operations with one encoder, with this change long press won't longer work. You may need to increase 1 second long click duration to make it work smoother, also only button releases need to be handled in client app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants