Memory game with sounds
Write a memory game in which you have to repeat the sounds played by the Powerbrain in the correct order.

This project is compatible with all eXperiBot sets.
This project requires an advanced understanding of how to work with variables, lists, and functions.
Task
Write a program that lets your Powerbrain play a random melody. You then have to replay that melody.
Your Powerbrain has, in addition to the start/stop button, three other buttons: A (or “-”), B (or “•”), C (or “+”). Each button should play a note when pressed.
The Powerbrain plays a random melody that you must replay with the buttons. Initially, the melody consists of only one note. If you play the melody correctly, the Powerbrain plays a melody of two notes. If you play the melody correctly again, the Powerbrain plays a melody of three notes, and so on.
As soon as a wrong note is played, the program terminates and the game is lost.
When the program starts, the Powerbrain plays each of the three notes once so you know how they sound. Then the game begins by the Powerbrain playing the first note, which must be replayed.
Setup
All you need for this project is a Powerbrain!
Hints
You need three different notes to be played in a random order. You can store these notes in a list as numerical values that represent the frequency of each note.
Here is a list of the frequencies for the notes C5, D5, and E5.
Pick a random item from your list and add it to another list that stores your melody. Also, play the sound using the “play sound with frequency” block.
You can now put the code to add new sounds into a loop and store the number of repetitions in a variable called “difficulty”.
To keep things organized, you can move your “melody generator” into a separate function. Add another function to check the melody that’s being played. This function should verify that the keys are being pressed in the correct order to repeat the melody.
Now it’s time to check the input from the keys and compare it to the melody. First, write another function that compares the first note in your “melody” list to a note that’s been played. If the comparison is successful, the element is removed from the list. If the comparison fails (i.e., if the wrong note was played), a “game over” melody is played and the program terminates.
To add an input parameter “note” to your function, use the gear icon right next to the function name.
Now the “check_note” function must be called from the ’check_melody’ function. Use an Infinite Loop to wait for keyboard input. As soon as a key is pressed, play the note and execute the “check_note” function. Break out of the Loop as soon as the “melody” list is empty—that is, when all notes have been played. Then increase the difficulty level by 1. Repeat “play_melody”, “check_melody,” and “change_difficulty_level” in an Infinite Loop.
Add three more “play note” blocks to the beginning of your program to play all three notes once.
Your memory game is now complete! How many sounds can you remember?
You can improve the program by storing the three frequencies in variables. Then you can easily change the frequencies to make the game harder or easier!
You can download the finished project here: