Arduino Memory Game

This project is dedicated to testing your memory. After a sequence of 4 LEDs, the user will attempt to correctly recall the order of lights and input their answer using the buttons. If the time runs up or the input is incorrect the RGB LED will turn red and the game will start over. Along with the red RGB the piezo buzzer will play a little song telling you the round is over. If the input is correct then the RGB will turn green and the piezo buzzer will play a song letting you know you won. Each round number will be displayed using a 7-Segment Display.
Supplies

For this project, here are the materials you will need...
1. Assorted LEDs x4
2. Arduino Uno x1
3.Resistors (x8 560 Ohms, x1 10K Ohms, x1 1K Ohms)
4.RGB LED x1
5. Arduino Uno x1
6. 4 Digit Seven Segment Display x1
7. Potentiometer (10k) x1
9. 555 Timer x1
9. Pushbutton x1
10. Electrolytic Capacitor (10 uF) x1
11. Wires
12.Bread Board
Inspiration
My inspiration for this project came from https://www.instructables.com/ARDUINO-MEMORY-GAME-2/
I believe it was a very well constructed project and fun game that made me want to try and create it for myself.
Wiring


Due to there not being enough pins the analog pins (A0-A5) were instead used as output pins for the 7-segment display. For the RGB LED only the red & blue pin were required which is why there is only 2 RGB pins attached to the Arduino. The green RGB doesn't have an Arduino pin because it is a common anode meaning it is always powered.
The Objective

This game features four differently colored LEDs, four buttons, an RGB LED, a piezo buzzer, and a 7-segment display. The objective is to memorize and input a randomly generated sequence by pressing the corresponding buttons. The game begins when the player presses any button. As the sequence is displayed using the LEDs, musical notes are played through the buzzer. The RGB LED lights up based on your performance, blue meaning you won and flashing red meaning game over indicating that the input was incorrect or the time limit was reached. The game has 5 rounds being counted on the 7-segment display.
The Code

Declare Constants & Variables
The Code 2

Set the roundsTowin to 5 to create a sequence array to store the button pattern and use roundcounter to count the rounds. Set pressedButton to 4 meaning no button is pressed initially. startTime and timeLimit are used to dictate how long a player has to recall and input the sequence. You can adjust the time based on your desired level of challenge. function, buttonPins are set as inputs, while ledPins, redRGB, blueRGB, buzzerPin, and the 7-segment segPins are all set as outputs to control the game’s components.
The Code 3

Use showDigit and digitalWrite() to turn segments segA to segB based off the bool values. The flashLED(int index) function lights up the LED at ledPins[index] and plays a tone from tones[index] using the buzzerPin, then turns both off after 200 ms. The setAllLEDs(bool on) function loops through all 4 ledPins and sets them either HIGH or LOW. The setRGB(int r, int b) function sets the brightness of the red and blue parts of the RGB LED using analogWrite() on redRGB and blueRGB. It only uses red and blue because the RGB LED is common anode.
The Code 4

The loop() function runs repeatedly and controls the game. If gameStarted is false, it calls startSequence() to start the pattern, resets roundCounter to 0, waits 1.5 seconds, and sets gameStarted to true. roundDisplay[roundCounter + 1]() shows the round number with the 7-segment display. startTime = millis() records the current time. It checks pressedButton using getButtonPressed() and if the correct button is pressed it continues and if wrong it calls loseSequence() to end the game. If the player has the correct input, roundCounter increases. If it reaches roundsToWin, the winSequence() activates and a short delay(500) gives a small break before the next round.
The Full Code
Thank you for reading.