Here are some ways to save RAM space in your sketch, apart from making the arrays smaller:
-
Define your pin numbers and other unchanging values as "const int" instead of plain "int".
-
When you want to print a string literal, use Serial.print(F("a string")) instead of Serial.print("a string"). To write a single character, use e.g. Serial.write(',') instead of Serial.print(",").
-
Where you use variables only locally, declare them locally, not at the global level. For example, you should declare rowCount and colCount in the for-loops that use them, not as global variables. Similarly for r0, r1, r2 and r3.
Using malloc() in your code will not help, it is more likely to make the problem worse.