UPDATE
I changed the code according to the answer by Majenko:
#include <HID-Project.h>
#include <HID-Settings.h>
uint8_t rawhidData[255];
byte rows[] = { 10, 16, 14 };
byte cols[] = { 9, 8, 7, 6, 5 };
const int rowCount = sizeof(rows)/sizeof(rows[0]);
const int colCount = sizeof(cols)/sizeof(cols[0]);
void setup() {
for (int row = 0; row < rowCount; row++) {
pinMode(rows[row], OUTPUT);
digitalWrite(rows[row], HIGH);
}
for (int col = 0; col < colCount; col++) {
pinMode(cols[col], INPUT_PULLUP);
}
RawHID.begin(rawhidData, sizeof(rawhidData));
}
void loop() {
for (int row = 0; row < rowCount; row++) {
digitalWrite(rows[row], LOW);
for (int col = 0; col < colCount; col++) {
if (digitalRead(cols[col]) == LOW) {
String coordinatesString = String(row+1) + String(col+1);
uint8_t coordinates = coordinatesString.toInt();
uint8_t megabuff[sizeof(coordinates)];
megabuff[0] = coordinates;
RawHID.write(megabuff, sizeof(megabuff));
while (digitalRead(cols[col]) == LOW) {
delay(50);
}
break;
}
}
digitalWrite(rows[row], HIGH);
}
}
I removed the serial output since I don't need that anymore. The code looks crude and needs further refactoring but it does work.