I have a 4x4 grid button grid and I want to print the coordinates of the button pressed in accordance to their x and y axis without making the original value of the grid itself ("whichButtonPressed" in this case) into a 2D array. The coordinates are roughly represented in the two arrays below:
int whichButtonPressed; // the button between 0 - 15 that is pressed
int xAxis[] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3};
int yAxis[] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3};
Serial.println(xAxis[whichButtonPressed]);
Serial.println(yAxis[whichButtonPressed]);
This works, but I feel as though it can be simplified in a way to where xAxis and yAxis are only arrays of 4 values each. I would also like to keep xAxis and yAxis as separate arrays instead of one 2D array.
For instance, if I press button 7 (the buttons read from top left to bottom right), I would like it to be something like:
xAxis[3];
yAxis[1];
If I've made my issue clear, how would I accomplish something like this?