Keypad .kstate question

mstanley:
OK, as I see things so far we've been working on the problem that you are having within your code and not your entire project. By working this way we've (I've) pretty much been ignoring the entirety of your program (sketch). The answers that I provided have ultimately led you to a dead-end solution where you will never get to your goal from here.

Using 7 different keypads with changing characters and matrices is that dead-end.

So let's do something different. Let's talk about your project. What are you trying to build? Just describe what a user is going to do when they walk up to your machine and what they expect to happen. And if you are OK with it then maybe I can help with code and explanations that are more in line with your expectations? We can talk about what hardware you are using and any other libraries that you may need and how they all can work together.

Best regards,
Mark

You definitely didn't steer me down a dead-end path.. My ambitions just got bigger as originally I was only having two Matricies one for buttons and the other for encoder and trying to get reads from certain pairs of buttons in order to allow a (greycode output) rotary encoder to be read correctly through the Keypad inputs.

For what I described in the last couple of posts I have actually got it working by just doing it the long way and setting up 7 Matricies, where different combinations of Matricies are triggered by an outside switch pair these run properly using a while statement that I setup so it only runs the correct functions for each matrix combination I need at one time based on the constant switch state.

So by example

By example I have two switches:

#1 - Switch #1 (OFF) & Switch #2 (OFF) a 4x7 matrix is active
#2 - Switch #1 (ON) & Switch #2 (OFF) a 3x7 matrix and a 1x7 matrix is active
#3 - Switch #1 (OFF) & Switch #2 (ON) a 2x7 matrix and a 2x7 matrix is active
#4 - Switch #1 (ON) & Switch #2 (ON) a 1x7 matrix and a 3x7 matrix is active

These different settings are being used to reallocate the Button Numbers for an HID Gaming device and to allow for a separate Matrix for the Encoders (Once I figure out how to deal with those). So basically doing this the long way is using up more space and probably memory but it is not really an issue as I still have plenty and I don't see this program expanding any further in scope.

Originally with the Multiple Matricies I was hoping that I could just reallocate the Matrix array that needs to be used to a common Matrix array so that I would only have to have one instance of the Button State loop. instead of different ones. This may still be able to be done which will make the program MUCH smaller but at the same time I have it running without this.

i.e.
if I have buttonKeypad and encoderKeypad as the two main matrix and that the matrixes from say #2, #3, or #4 above could be transferred into. Such as Option #2 is Created Key Array 3x7 (keypad21) + Created Key Array 1x7 (keypad7) could be reinitialized to keypad21 = buttonKeypad and keypad7 = encoderKeypad and so on so that the same function code can be used.

BUT as I mentioned technically I have everything regarding the Matrix allocation worked out the long way with a different function for each.

So now I am back at the encoders and getting correct reads from them which I thought I had working but it turns out when I actually hooked it all up to the computer as the HID Device to test the encoder set-up didn't work properly at all. So I got what I thought was right as it worked with Serial Output checks but there was other stuff going on between the prints that I didn't know was going on ..

So in the end what I am trying to do is to figure out how to track two specific Keypad buttons in a loop to determine when each button is pressed and released in relation to each other, This would be the two outputs of the Greycode encoder and then would allow me to determine which direction the encoder is turning (via the comparison) and at what point I need to send a Button (ON and OFF).

So let me run by my current thinking and what I asked if there was a way to use get.state of a specific Key. From what I understand from our prior conversation getkeys with get a list of ALL active keys at a specific time regardless of what key is pressed. For each loop that getkeys runs it puts the first active key into position 0 and then any subsequent keys after that.

So I am currently thinking that during a single loop I can use the find key command to find if the keys that I need are active or not i.e I can findinlist #9 and then findinlist #10 which would be the encoder pair and it should return 1 or -1 for each depending on whether to not they are in the list?

So if say I cal GetKeys and then call encA = kpd.findInList('9') and encB = kpd.findInList('10')

The it should return:

encA = -1, encB = -1 if neither are in the list
encA = 1, encB = -1 if A is in the list
encA = -1, encB = 1 if B is in the list
encA = 1, encB = 1 if both are in the list

If I am correct on this I may be able to get this to work the way I want I will just have to continuously poll the matrix with the geyKeys.

Right now I had it set up to run an Event so tha it only polled upon that event which of course would only take a snapshot of the GetKeys for that particular loop.. Which of course would send things out of scope on the next activation of the event, which I think is where I was having things work in serial but not in reality and I could determine a direction by just the initial button press (though the other button was also pressed but not registered by the event directly).

I hope this explains a bit about my questions and intensions and what I actually have working.. But basically I am stuck at the point of being able to compare the activation and state of two pairs buttons.. ie 9/10, 11/12, 21/22, 25/26 ect...