-
-
Save buildcircuit/3904d772d74241cb91df1542e92aa41d to your computer and use it in GitHub Desktop.
Basic Scoreboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <RGBmatrixPanel.h> | |
#define CLK 8 // USE THIS ON ARDUINO UNO, ADAFRUIT METRO M0, etc. | |
#define OE 9 | |
#define LAT 10 | |
#define A A0 | |
#define B A1 | |
#define C A2 | |
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false); | |
// Score variables | |
int leftScore = 0; | |
int rightScore = 0; | |
void setup() { | |
Serial.begin(9600); | |
matrix.begin(); | |
// Display "A" in red on the left, on top of leftScore | |
matrix.setCursor(2, 2); | |
matrix.setTextSize(1); | |
matrix.setTextColor(matrix.Color333(7, 0, 0)); | |
matrix.print("A"); | |
// Display "B" in blue on the right, on top of rightScore | |
matrix.setCursor(18, 2); | |
matrix.setTextColor(matrix.Color333(0, 0, 7)); | |
matrix.print("B"); | |
matrix.swapBuffers(false); // Display the initial frame | |
} | |
void loop() { | |
if (Serial.available() > 0) { | |
char command = Serial.read(); | |
switch (command) { | |
case 'X': | |
// Up count for left score | |
leftScore++; | |
break; | |
case 'Y': | |
// Down count for left score | |
leftScore--; | |
break; | |
case 'E': | |
// Up count for right score | |
rightScore++; | |
break; | |
case 'F': | |
// Down count for right score | |
rightScore--; | |
break; | |
} | |
// Update display | |
updateDisplay(); | |
} | |
} | |
void updateDisplay() { | |
// Clear the display | |
matrix.fillScreen(matrix.Color333(0, 0, 0)); | |
// Draw "A" in red on the left, on top of leftScore | |
matrix.setCursor(2, 0); | |
matrix.setTextSize(1); | |
matrix.setTextColor(matrix.Color333(7, 0, 0)); | |
matrix.print("A"); | |
matrix.setCursor(2, 10); | |
matrix.print(leftScore); | |
// Draw '-' between leftScore and rightScore | |
matrix.setCursor(12, 10); | |
matrix.setTextColor(matrix.Color333(7, 7, 7)); | |
matrix.print("-"); | |
// Draw "B" in blue on the right, on top of rightScore | |
matrix.setCursor(18, 0); | |
matrix.setTextColor(matrix.Color333(0, 0, 7)); | |
matrix.print("B"); | |
matrix.setCursor(18, 10); | |
matrix.print(rightScore); | |
matrix.swapBuffers(false); // Display the updated frame | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment