Encoder icon indicating copy to clipboard operation
Encoder copied to clipboard

Feature: getDirection()

Open dicagno opened this issue 2 years ago • 2 comments

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

--

dicagno avatar May 06 '23 05:05 dicagno

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);
  }
}

bwalc0 avatar Dec 13 '23 16:12 bwalc0

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

dicagno avatar Dec 17 '23 12:12 dicagno