Steve2381
Senior Member
Hello
I have an MCP23016 I/O expander chip running on I2c. Its got 16 input/outputs. I have these wired as an 8x8 button matrix (8x outputs, and 8x inputs). I am using 8 pins as outputs for columns and 8 pins for inputs as rows. 64 detectable buttons.
I am sequentially taking each of the 8 of the outputs high, and then reading the results of that line of 8 buttons using the other 8 input pins. It returns a value according to the button that is pressed.
so for each column of buttons, I get the results (if the are pressed individually)
1= button 1
2= button 2
4= button 3
8= button 4
16= button 5
32= button 6
64= button 7
128= button 8
This all works fine (if not a bit slow).
My question is, does anyone know of a nice smart way of deducting what button has been pressed, considering it might be a combination of buttons.
The result ideally would be a something like Button1=1 when its been pressed.
But, there are obviously a large number of possible outcomes. E.G. Buttons 1, 4 and 7 would equal 39. That is a lot of 'if' statements. And that is just one of the 8 rows of results to check.
I am then reading the final button press result from another chip using this 40x2 as a slave I2c.
I think by the time I get it scanning and deducing all 8 rows, this may have to be bumped off the 40x2 onto an Arduino simply due to the speed issue, but I will deal with that later.
When i get in tonight, I will lift the code and post it if I can.
I have an MCP23016 I/O expander chip running on I2c. Its got 16 input/outputs. I have these wired as an 8x8 button matrix (8x outputs, and 8x inputs). I am using 8 pins as outputs for columns and 8 pins for inputs as rows. 64 detectable buttons.
I am sequentially taking each of the 8 of the outputs high, and then reading the results of that line of 8 buttons using the other 8 input pins. It returns a value according to the button that is pressed.
so for each column of buttons, I get the results (if the are pressed individually)
1= button 1
2= button 2
4= button 3
8= button 4
16= button 5
32= button 6
64= button 7
128= button 8
This all works fine (if not a bit slow).
My question is, does anyone know of a nice smart way of deducting what button has been pressed, considering it might be a combination of buttons.
The result ideally would be a something like Button1=1 when its been pressed.
But, there are obviously a large number of possible outcomes. E.G. Buttons 1, 4 and 7 would equal 39. That is a lot of 'if' statements. And that is just one of the 8 rows of results to check.
I am then reading the final button press result from another chip using this 40x2 as a slave I2c.
I think by the time I get it scanning and deducing all 8 rows, this may have to be bumped off the 40x2 onto an Arduino simply due to the speed issue, but I will deal with that later.
When i get in tonight, I will lift the code and post it if I can.