Does anyone have experience using the PinChangeInt library on an Arduino Mega 2560? I'm trying to connect a bunch of limit switches to Port K but they don't seem to be working. Since I have multiple switches I need both PCintPort::arduinoPin and PCintPort::pinState but when I try storing those values to more permanent variables and then printing them, I get 0 for both. What am I doing wrong?
Here is the ISR that I'm trying to use. I tried saving arduinoPin and pinState to int's before printing them. Anything in all caps is a #define constant from the beginning of the code so assume it's a number.
void limitAlert() {
int x = (PCintPort::arduinoPin - LIMITSWITCH_1B) / 2;
if (PCintPort::pinState == HIGH) {
limitStates[x] = 0;
} else if (PCintPort::arduinoPin % 2 == 0) {
limitStates[x] = -1;
} else {
limitStates[x] = 1;
}
if (PCintPort::arduinoPin % 2 == 0) {
motorPositions[x] = 0;
} else {
switch (x) {
case 0:
motorPositions[x] = MAX_ENCLOSURE_TRAVEL;
break;
case 1:
motorPositions[x] = MAX_ARM_EXTENSION;
break;
case 2:
motorPositions[x] = MAX_ARM_WIDTH;
}
}
digitalWrite(DRIVER1_E12 + x * 3, PCintPort::pinState);
}