Hello all,
I am nearing completion for a project I've been working on, and would appreciate any help!
I was originally using a rotary encoder by reading the pins until I realized/was told how ineffecient and how I could miss pulses that way.
Since, I have been using this library: GitHub - PaulStoffregen/Encoder: Quadrature Encoder Library for Arduino
By reading pins I was able to distinguish between output A and output B to directionalize the encoder, however since using the library, I have not been able to find a way to do so considering that the myEnc.read() only ever returns a positive value, regardless of the direction of rotation.
Is there a way I can use this library to detect direction of rotation?
Thank you very much!
This is the library example I was referencing:
#define ENCODER_DO_NOT_USE_INTERRUPTS
#include <Encoder.h>
Encoder myEnc(5, 6);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
Serial.println("Basic NoInterrupts Test:");
}
long position = -999;
void loop() {
long newPos = myEnc.read();
if (newPos != position) {
position = newPos;
Serial.println(position);
}
}
Here is my attempted implementation with directions.
long newPos = myEnc.read();
if (newPos != position)
{
if (newPos < position)
{
inches = inches - (0.03926990816 * pitchDiameter);
}
else if (newPos > position)
{
inches = inches + 0.03926990816 * pitchDiameter;
}
position = newPos;
}