#include <LedControl.h>
// Initialize the LedControl library
LedControl lc=LedControl(12, 11, 10, 1);
// Initialize variables for the game
int playerScore = 0;
int computerScore = 0;
int roundsPlayed = 0;
int playerChoice = -1;
int computerChoice = -1;
// Initialize pins for the 7-segment displays
const int scoreDisplayPins[] = {2, 3, 4, 5};
const int numDisplayPins = sizeof(scoreDisplayPins)/sizeof(scoreDisplayPins[0]);
// Initialize pins for the pushbutton
const int buttonPin = 6;
void setup() {
// Initialize the matrix and clear it
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
// Initialize the 7-segment displays
for (int i = 0; i < numDisplayPins; i++) {
pinMode(scoreDisplayPins[i], OUTPUT);
}
// Initialize the pushbutton
pinMode(buttonPin, INPUT_PULLUP);
// Set the seed for the random number generator
randomSeed(analogRead(0));
}
void loop() {
// Display the scores
displayScore(playerScore, 0);
displayScore(computerScore, 1);
// Wait for the button to be pressed
while (digitalRead(buttonPin) == HIGH) {
// Do nothing
}
// Get the player's choice
playerChoice = getPlayerChoice();
// Generate a random choice for the computer
computerChoice = random(0, 3);
// Determine the winner and update the scores
if (playerChoice == computerChoice) {
// Tie
} else if ((playerChoice == 0 && computerChoice == 1) || (playerChoice == 1 && computerChoice == 2) || (playerChoice == 2 && computerChoice == 0)) {
// Player wins
playerScore++;
} else {
// Computer wins
computerScore++;
}
// Increment the number of rounds played
roundsPlayed++;
// Display the winner
displayWinner(playerChoice, computerChoice);
// Delay to give the player time to see the winner
delay(2000);
// Clear the winner display
clearWinnerDisplay();
// Check if the game is over
if (roundsPlayed == 10) {
// Display the final scores and winner
displayFinalScore();
// Reset the game
resetGame();
}
}
// Displays the player and computer scores on the 7-segment displays
void displayScore(int score, int displayNum) {
int digits[4];
// Convert the score to an array of digits
digits[0] = score / 1000;
digits[1] = (score / 100) % 10;
digits[2] = (score / 10) % 10;
digits[3] = score % 10;
// Set the appropriate segments on the 7-segment displays
for (int i = 0; i < 4; i++) {
digitalWrite(scoreDisplayPins[i], HIGH);
lc.setDigit(displayNum, i, digits[i], false);
digitalWrite(scoreDisplayPins[i