Skip to content

No interrupt call function needed #13

@DocAlex

Description

@DocAlex

Hello,

thank you for providing this code.

You are attatching the interrupt to an helper function to call the opject read_AB. This is not necessary. Instead using

attachInterrupt(digitalPinToInterrupt(PIN_A), encoderISR, CHANGE); //call encoderISR() every high->low or low->high changes

You can use:

attachInterrupt(digitalPinToInterrupt(PIN_A), []() {
       encoder.readAB();
    }, CHANGE);

make sure "encoder" has been declared in this context.

This approach is called "lambda function" and is even faster.

Thank you again

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions