#include <RGBmatrixPanel.h>
// Pins for Arduino Mega
#define CLK 11
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);
// Scoreboard variables
String teamName = "TEAM";
String scoreStr = "0/0";
String oversStr = "0.0";
String bat1 = "";
String bat2 = "";
String inputString = "";
// ---------------- SETUP ----------------
void setup() {
Serial.begin(115200);
Serial.println("Cricket Scoreboard Ready.");
Serial.println("Use TEAM=, SCORE=, OVER=, BAT1=, BAT2=");
matrix.begin();
matrix.fillScreen(matrix.Color333(0, 0, 0));
drawScoreboard();
}
// ---------------- LOOP ----------------
void loop() {
while (Serial.available()) {
char c = Serial.read();
if (c == '\n') {
processCommand(inputString);
inputString = "";
}
else if (c >= 32 && c <= 126) {
inputString += c;
}
}
}
// Process commands like TEAM=India
void processCommand(String cmd) {
cmd.trim();
if (cmd.startsWith("TEAM=")) {
teamName = cmd.substring(5);
}
else if (cmd.startsWith("SCORE=")) {
scoreStr = cmd.substring(6);
}
else if (cmd.startsWith("OVER=")) {
oversStr = cmd.substring(5);
}
else if (cmd.startsWith("BAT1=")) {
bat1 = cmd.substring(5);
}
else if (cmd.startsWith("BAT2=")) {
bat2 = cmd.substring(5);
}
drawScoreboard();
}
// ---------------- DRAW SCOREBOARD ----------------
void drawScoreboard() {
matrix.fillScreen(matrix.Color333(0,0,0));
// Team Name (Top)
matrix.setTextColor(matrix.Color333(7,7,0)); // Yellow
matrix.setTextSize(1);
matrix.setCursor(0, 0);
matrix.print(teamName);
// Score (big)
matrix.setTextColor(matrix.Color333(7,7,7)); // White
matrix.setTextSize(2);
matrix.setCursor(0, 8);
matrix.print(scoreStr);
// Overs
matrix.setTextSize(1);
matrix.setTextColor(matrix.Color333(0,7,7)); // Cyan
matrix.setCursor(0, 24);
matrix.print("Ov: ");
matrix.print(oversStr);
// Batsmen lines
matrix.setCursor(32, 0);
matrix.setTextColor(matrix.Color333(0,7,0)); // Green
matrix.print(bat1);
matrix.setCursor(32, 8);
matrix.setTextColor(matrix.Color333(0,7,0));
matrix.print(bat2);
}