neu-rah / ArduinoMenu

Arduino generic menu/interactivity system
GNU Lesser General Public License v2.1
931 stars 189 forks source link

encoder and Teensy isn't accurate. #380

Open woodencase01 opened 2 years ago

woodencase01 commented 2 years ago

I used this library in the past with good success: https://github.com/PaulStoffregen/Encoder using interrupt pins(all pin are interrupt capable) from the Teensy (6 & 7)

Keeping the same hardware setup, I switched to the provided "<menuIO/encoderIn.h>". However, I started having strange behavior such as not moving as the encoder rotates, or moving more than supposed (sometimes scrolling for one second).

Here is my code regarding the encoder:

const uint8_t encA = 6;
const uint8_t encB = 7;
encoderIn<encA, encB> encoder;
encoderInStream<encA, encB> encStream(encoder, 4);

menuIn *inputsList[] = {&encStream, &encButton};
chainStream<2> in(inputsList);

Is there something I did wrong? Is there a way I could use the original library from Paul for the encoder?

woodencase01 commented 2 years ago

Ok, I just found "#include <menuIO/rotaryEventIn.h>" and it solved my problem.

Using Paul library, I got the encoder to work wonderfully.

Thanks for providing this example code. Here is my current knob code:

void updateKnob()
{
    int32_t newKnobPosition = knob.read();
    deltaKnobPosition = newKnobPosition - currentKnobPosition;
    if (newKnobPosition != currentKnobPosition && (deltaKnobPosition % 4) == 0) // The knob has turned and the turn is finished (4 increments)
    {
        currentKnobPosition = newKnobPosition;
        if (deltaKnobPosition > 0)
        {
            reIn.registerEvent(RotaryEventIn::EventType::ROTARY_CW);
        }
        else
        {
            reIn.registerEvent(RotaryEventIn::EventType::ROTARY_CCW);
        }
    }
}