OK I have some code that I have written which works well for 2 locations in the matrix. It is running on a Teensy LC
void encoderEvent(KeypadEvent enccheck){
A = enccheck;
B = enccheck;
// Determine Active Encoder A or B
if (enccheck != 0){
if (enccheck != NO_KEY){
if ( enccheck % 2 == 0){
A = enccheck - 1;
Astate = encodermatrix.key[A].kstate;
Bstate = encodermatrix.key[B].kstate;
Serial.print("Astate ");
Serial.print(Astate);
Serial.print(", Bstate ");
Serial.println(Bstate);
EncoderState();
}else{
B = enccheck + 1;
Astate = encodermatrix.key[B].kstate;
Bstate = encodermatrix.key[A].kstate;
Serial.print("Astate ");
Serial.print(Astate);
Serial.print(", Bstate ");
Serial.println(Bstate);
EncoderState();
}
}
}
}
This event code runs when a button has been pressed on the Matrix (Keypad) , when the button is pressed it passes the byte enccheck to the event which is the number of the button being pressed.
The if statements determine whether the button being pressed is odd or even and then creates a second button number to be used as its pair putting an odd button number into A and an even button Number into B and then finding the .kstate of each of those buttons A and B and defining them as Astate, and Bstate.
After that the Astate and Bstate are run through a dual stage switch statement which checks the Estate and Bstate and then outputs a grey code based on the Pressed or released state of each button.
The issue I am having is that everything works perfectly for Keys 1 and 2 on the keypad but when 3 and 4 or 5 and 6 or anything beyond 1 and two are paired up the encodermatrix.key[A].kstate and encodermatrix.key**.kstate ALWAYS returns an IDLE (0) state.. A and B are 3 and 4, or 5 and 6 so I am thinking it should get the kstate of 3 and 4 or 5 and 6 and then be fine going through the switch to output the Gray code for those pairs but it doesn't seem to be working that way as previously said it always returns IDLE even when pressed.**
So I am confused and I think I am missing something, maybe it is a variable type issue everything is a byte.. I just don't know.. seems like it should work..
BTW the IDLE states pass through the switch as IDLE and IDLE and I have verified the Key Number is running into and through the switch so it is something in the calling of .kstate with numbers higher than 2