Hey,
my setup:
Arduino Mega 2560
Rotary Encoder (similar to this)
I am using a rotary encoder to scroll through a menu on a tft display connected to my Arduino Mega 2560. I am using the following library for debouncing using interrupts, which works pretty well: Rotary
Up until now I connected Channel A and B to pins 2 and 3 respectively. Since the display covers these two pins, I now want to change it to pins 18, 19, 20 or 21. These should be interrupt pins according to attachinterrupt.
However, although my code works without problems with pins 2 and 3, it shows faulty behaviour when using any of the other pins (either not firing the interrupt at all or very slowly and buggy). My code snippet is as follows:
#include <Rotary.h>
Rotary rotary = Rotary(18, 19);
void setup()
{
Serial.begin(57600);
attachInterrupt(0, drawCursor, CHANGE);
attachInterrupt(1, drawCursor, CHANGE);
}
void drawCursor() {
unsigned char result = rotary.process();
int menueEintraege;
if (result == DIR_CW)
{
Serial.println("CW");
tft.fillRect(1, 41, 30, 197, BLACK);
rotary_counter++;
} else if (result == DIR_CCW)
{
Serial.println("CCW");
tft.fillRect(1, 41, 30, 197, BLACK); // Cursor-Bereich loeschen
rotary_counter--;
}
}
Any ideas why it is not working with the other interrupt pins?
Thanks!
Dev
P.S.: Well, I found the mistake myself... I must attach to the correct pins (5 and 4). Thread can be deleted if mods want. Thanks