# Serial.Print Matrix 8x8

Hi, i used an old dartboard matrix on an Arduino Uno.
Now if i touch on the dartboard it shows the reading in de Serial monitor like 2,3 or 5,1 or...
Can i change something in the code, so i can read the real number like on the dartsboard like 20, 19, double 4 etc.... Do i use if or map the whole thing...?

My code for now;

``````int masterLines = 8;
int slaveLines = 8;

int matrixMaster[] = {13, 12, 11, 10, 9, 8, 7, 6};
int matrixSlave[] = {5, 4, 3, 2, A5, A4, A3, A2};

void setup() {
Serial.begin(9600);
Serial.println("Mijn Darts");

for(int i = 0; i < slaveLines; i++){
pinMode(matrixSlave[i], INPUT_PULLUP);
}

for(int i = 0; i < masterLines; i++){
pinMode(matrixMaster[i], OUTPUT);
digitalWrite(matrixMaster[i], HIGH);
}
}

void loop() {
for(int i = 0; i < masterLines; i++){
digitalWrite(matrixMaster[i], LOW);
for(int j = 0; j < slaveLines; j++){
Serial.print(j);
Serial.print(",");
Serial.println(i);
delay(500);
break;
}
}
digitalWrite(matrixMaster[i], HIGH);    }    }

``````

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

You seem to be getting back the x and y coordinates of the point that you touched. If so, then you could use a 2 dimensional array to hold the values for each of the positions on the board and use the x and y coordinates to access the value at that point

I think you meen this

``````int Matrix[8][8] = {{'A','B','C','D','E','F','G','H'},
{'A','B','C','D','E','F','G','H'},
{'A','B','C','D','E','F','G','H'},
{'A','B','C','D','E','F','G','H'},
{'A','B','C','D','E','F','G','H'},
{'A','B','C','D','E','F','G','H'},
{'A','B','C','D','E','F','G','H'},
{'A','B','C','D','E','F','G','H'} };
``````

But how do change the Serial.Print,
I meen this part so it uses the wright caracter on the serial monitor

``````void loop() {
for(int i = 0; i < masterLines; i++){
digitalWrite(matrixMaster[i], LOW);
for(int j = 0; j < slaveLines; j++){
Serial.print(j);
Serial.print(",");
Serial.println(i);
delay(500);
break;
}
``````

If you want characyers in the array then declare it as type char instead of int

Once you have the two values then you can use them as the indices to the array. Something like

``````Serial.println(Matrix[j][i]);
``````

Incidentally, it would make more sense to refer to the two axis values as x and y as this would be the conventional way

Yes, i have it working how i want, exept i cant get 2digits in the print.
Number with 2 digits only show the last digit

``````char Matrix[8][8] = {{'1','12','5','7','9','13','4','0'},
{'1','12','5','7','9','13','4','0'},
{'1','12','5','7','9','13','4','0'},
{'1','12','5','7','9','13','4','0'},
{'1','12','5','7','9','13','4','0'},
{'1','12','5','7','9','13','4','0'},
{'1','12','5','7','9','13','4','0'},
{'1','12','5','7','9','13','4','0'} };
``````

Now it shows only 1 digit, i should be able to see on the serial monitor from 1 to 20, Double 1 to 20, Triple 1 to 20 and Bullseye

A char can only hold a single character

Change the matrix declaration to use byte instead of char and remove the quotation marks from the values in the array to see the values then we can deal with text like "Bullseye" and "Double"

It will require another change, but let's build up to that

if i use

``````byte Matrix[8][8] = {{15,27,33,48,57,51,45,18},
``````

it shows the two digits.
But for example the 15 should be shown as Triple 5

is there a way to combine characters and digits?

Now that you have the basic array working it is time to delve into the wonderful world of pointers

Try this example them make the relevant changes to your Matrix array

``````const char * Matrix[2][2]
{
{"one", "two"},
{"three", "four"}
};

void setup()
{
Serial.begin(115200);
while (!Serial);
for (int row = 0; row < 2; row++)
{
for (int col = 0; col < 2; col++)
{
Serial.println(Matrix[row][col]);
}
}
}

void loop()
{
}``````

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.