brianlow / Rotary

Rotary encoder library for Arduino
233 stars 73 forks source link

Adding inline get methods to access encoder pins. #21

Closed SteveGuidi closed 1 year ago

SteveGuidi commented 1 year ago

Allows for read-only retrieval of the encoder's A/B pins after construction.

brianlow commented 1 year ago

Thanks for opening this PR. What is the motivation for the change?

SteveGuidi commented 1 year ago

Hi Brian:

I'm working with a generalized module that will attach an ISR function for a given pair of rotary encoder pins. I'd like to be able to pass an instance of Rotary to this function so that the pins may be inferred instead of provided explicitly -- that way, there is no chance that a user may configure Rotary with one pair of pins, but accidentally define interrupts for an unrelated set of pins.

Psuedo-code example:

void Initialize(const Rotary& encoder) {
    enableInterrupt(encoder.pin_1(), onEncoderPinChange, RISING);
    enableInterrupt(encoder.pin_2(), onEncoderPinChange, RISING);
};
brianlow commented 1 year ago

I see, thanks for the explanation

brianlow commented 1 year ago

Thanks again for the PR

SteveGuidi commented 1 year ago

Thank you, and glad to be of help!