Decoding a 4x16 Switch Matrix on Arduino for Conditional Logic
I'm looking to decode an existing switch matrix (4 Rows and 16 Columns, basically copy the states of the Rows and Columns).
The goal is to ultimately have a [data] where I will have:
ROW 1 == LOW && COL 1 == LOW, which will result in DATA == LOW.
In my case, only INPUTs are needed, the Arduino should not generate the matrix but only read it (so no OUTPUTs).
After obtaining this variable [DATA], I need to add a condition Supp [DATA] && x == 1 to store it in another variable in order to pass it into a SWITCH CASE.
Then, I can do things like: (but I have 64 switches)
The goal is to ultimately have a [data] where I will have:
ROW 1 == LOW && COL 1 == LOW, which will result in DATA == LOW.
In my case, only INPUTs are needed, the Arduino should not generate the matrix but only read it (so no OUTPUTs).
After obtaining this variable [DATA], I need to add a condition Supp [DATA] && x == 1 to store it in another variable in order to pass it into a SWITCH CASE.
Then, I can do things like: (but I have 64 switches)
4 Replies
I haven’t found any code that allows me to solve this issue.
Solution
Use a nested loop instead of the switch.
The MatrixKeypad library does this very well. https://github.com/victorsvi/MatrixKeypad You can install it from the IDE's library manager.
GitHub
GitHub - victorsvi/MatrixKeypad: Simple to use Arduino library to i...
Simple to use Arduino library to interface matrix keypads. - victorsvi/MatrixKeypad