Hi all !
I'm using an encoder library, to read a rotary encoder using 2 analog ports. The library is : GitHub - mathertel/RotaryEncoder: RotaryEncoder Arduino Library
The example given uses pins A2 and A3, but in my project I need to attach the encoder to ports A13 and A14 of my Arduino Mega.
This is the setup part of the original example "InterruptRotator":
// Setup a RoraryEncoder for pins A2 and A3:
RotaryEncoder encoder(A2, A3);
void setup()
{
Serial.begin(57600);
Serial.println("SimplePollRotator example for the RotaryEncoder library.");
// You may have to modify the next 2 lines if using other pins than A2 and A3
PCICR |= (1 << PCIE1); // This enables Pin Change Interrupt 1 that covers the Analog input pins or Port C.
PCMSK1 |= (1 << PCINT10) | (1 << PCINT11); // This enables the interrupt for pin 2 and 3 of Port C.
}
I've tried to find the way to adapt this to my project as it follows :
// Setup a RoraryEncoder for pins A13 and A14:
RotaryEncoder encoder(A13, A14);
void setup()
{
Serial.begin(57600);
Serial.println("SimplePollRotator example for the RotaryEncoder library.");
// You may have to modify the next 2 lines if using other pins than A13 and A14
PCICR |= (1 << PCIE2); // This enables Pin Change Interrupt 1 that covers the Analog input pins or Port K.
PCMSK2 |= (1 << PCINT21) | (1 << PCINT22); // This enables the interrupt for pin 5 and 6 of Port K.
} // setup()
But doesn't work, each time I turn one encoder step, the initial message appears 4 times as the program was restarting 4 times. The same example works for ports A2 and A3
For sure I'm missing something because I don't really know how this interrupt enable works, but I can't find more information.
Thanks for your help,
Eloi