Nano Every Encoder interrupt error

The Encoder library has not had support for the ATmega4809 microcontroller of the Nano Every added yet.

Since all the microcontroller-specific code in the library is for interrupts, the workaround should be to use the "ENCODER_DO_NOT_USE_INTERRUPTS" mode of the library, as demonstrated in the library's NoInterrupts example.

However, there seems to be a bug in the Encoder library when used in this mode. I believe I have a fix for the bug:

Open /Users/eraxeg/Documents/Arduino/libraries/Encoder/Encoder.cpp in a text editor.

Add the following line to the very top of the file:

#define FROM_ENCODER_CPP

Save the file.

Open /Users/eraxeg/Documents/Arduino/libraries/Encoder/Encoder.h in a text editor.

Change line 43 from:

#if defined(ENCODER_USE_INTERRUPTS) || !defined(ENCODER_DO_NOT_USE_INTERRUPTS)

to:

#if defined(ENCODER_USE_INTERRUPTS) || (!defined(ENCODER_DO_NOT_USE_INTERRUPTS) && !defined(FROM_ENCODER_CPP))

Save the file.

After that, you should be able to use the library with your Nano Every when in "ENCODER_DO_NOT_USE_INTERRUPTS" mode. Make sure to carefully read and understand the comments at the top of the NoInterrupts example.