Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

No interrupt call function needed #13

Open
DocAlex opened this issue Nov 28, 2024 · 0 comments
Open

No interrupt call function needed #13

DocAlex opened this issue Nov 28, 2024 · 0 comments

Comments

@DocAlex
Copy link

DocAlex commented Nov 28, 2024

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant