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

Feature: getDirection() #93

Open
dicagno opened this issue May 6, 2023 · 2 comments
Open

Feature: getDirection() #93

dicagno opened this issue May 6, 2023 · 2 comments

Comments

@dicagno
Copy link

dicagno commented May 6, 2023

Description

A method to determine step direction is missing and would be a great nice-to-have.

Steps To Reproduce Problem

No method to get step direction.

Hardware & Software

Board: any
Shields / modules used: any

Usage

int direction = encoder.getDirection();
// 1 -> forward
// -1 -> backwards
// 0 -> no movement

Errors or Incorrect Output

--

@bwalc0
Copy link

bwalc0 commented Dec 13, 2023

If you would like to use it, I have edited Examples -> Basic

long oldPosition  = -999;

void loop() {
  long newPosition = myEnc.read();

  int direction = 0;
  if (newPosition != oldPosition) { 

    direction = (newPosition > oldPosition) ? 1 : -1;

    oldPosition = newPosition;
    Serial.println(newPosition);
  }
}

@dicagno
Copy link
Author

dicagno commented Dec 17, 2023

@bwalc0 thanks for the answer. Did you take a look at the associated PR?

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

No branches or pull requests

2 participants