RGBY (Red, Green, Blue, Yellow) a Memory Game
by kewang532 in Circuits > Raspberry Pi
39 Views, 1 Favorites, 0 Comments
RGBY (Red, Green, Blue, Yellow) a Memory Game

I created a 4 color memory game, hence the name RGBY, and essentially, the board shows a color pattern, then you enter the same pattern with 4 input buttons. If you get it right 3 times in a row, there will be some RGB lights flashing to let you know you completed 3 stages. You have 3 lives each game, and they are displayed on the RGB LED, green is when you have 3 lives left (yay!), yellow when you have 2 (oh no), and red when you have only one life left (work it brain!).
There are also 4 game modes you can chose upon startup, Solo, Timed, Advanced, and PvP (1v1 against a friend!). It is a extremely fun game to play when you are bored, if you and your friends are bored, such as on a field trip (tell your teacher it's a project) in school, road trips with your family, and just when you want to play with you brothers and sisters (or cousins and friends, maybe even 1v1 against your teacher!). For 1v1, a RGB LED displays your health when it is your turn, and your opponents when it's theirs.
For advanced, the light flashes for only a very small amount of time (randomly from 0.5-1 second) so it is way harder.
For timed, you must press the correct button every between 1-2 seconds or you will lose a life.
I will be mainly using the Raspberry Pi Pico for this project as a microcontroller to control and program the game (see further in this instructables for more details).
Supplies

I am using:
- A Computer to write code onto, preferably Windows 10 or 11 for compatibility
- A Raspberry Pi Pico Board (PICO 2 is essentially the same as 1, but faster clock speeds and greater memory, I bought my Pico 1 last year) here's the link to Amazon for the Pico 2 with headers: Raspberry Pi Pico 2 (All links are non-affiliated)
- LEDs
- A software to write code on (I used notepad, as you can drag files to the Pico board on your computer, but you can also use Arduino IDE if you prefer)
- Buttons for the inputs: Buttons with color (I used normal buttons, that's fine, it's just that these have colored tips)
- Varying Ohm Resistors
- Preferably 8ohm speakers: Set of 2 8ohm speakers
- LM368 Speaker Amplifier (Instructables here Credits to abzza for this instructable)
- Mini Breadboard
- Wires for connecting items to breadboard
- Cardboard
- Hot Glue Gun (You can easily get it cheaper at your local hardware store vs Amazon)
- Hot Glue sticks (You can also get at your local hardware store)
- Thonny IDE for transferring code to your Pico
- I used Cursor and Visual Studio Code to create my program
Computer Programs

Setting Up Firmware for the Pico




To setup and/or to update MicroPython firmware for the Raspberry Pi Pico, go to the official Raspberry Pi website and find the version your Raspberry Pi Pico is. If it is Pico 1, then download the Pico 1 firmware .uf2 package. If it is a Raspberry Pi Pico Wifi, download the Raspberry Pi Pico W for your Pico, and so on.
Once downloaded (this shouldn't take so long), press the button labeled "BOOTSEL" on your Pico, and plug it into your computer while holding the BOOTSEL button. You should see something pop up in file explorer like shown above in my images, it should be labeled "RPI-RP2".
Then, navigate to your downloads file. You should see the recently downloaded .uf2 file. Click on it and press "copy" in the top left corner as shown above. Now, navigate back to your Pico's drive, and press "paste" in the top left corner. You should see that your Pico disconnects then reconnects. Now your firmware is ready for your Pico.
Verifying the Pico



Okay. Now open the Thonny app you just downloaded earlier. Make sure your Pico is plugged in, and that you have finished downloading the firmware.
Select tools, then select options, then interpreter, then select the board you're using (in this case MicroPython Raspberry Pi Pico). You should see the COM port it is connected to, and what device it is in the lower right corner.
To further verify, let's run a simple code for the Raspberry Pi Pico to execute and say "Hello!". In the current terminal, copy paste this code: print("Hello!") After, press enter. The result should be "Hello!" (I have made a instructables previously explaining print function in Python). If not, then repeat step 2 and 3.
Or if you installed the wrong firmware/bricked pico, press and hold the BOOTSEL button, then insert the usb into your computer then load (copy paste) this nuke.uf2 file that will erase all memory, including the firmware (nuke.uf2 github) so you will have to reinstall the firmware again after nuking the Pico.
Code



Open this file (Python code) with Thonny. Inside Thonny, press the save icon as shown in above image. You will then get prompted to chose for this computer or Raspberry Pi Pico. Chose Raspberry Pi Pico, then name the file as "main.py", press save changes, or save file.
Now your code is ready, and the only step left is to wire the hardware to the Pico and make the stand!
P.S. You can actually run the code now, and you will see the title Rainbow Memory Game, and the options to chose game modes.
Downloads
Wiring

Place your Raspberry Pi Pico onto the mini breadboard like so, so the micro usb slot is facing the end, and the pin 0 is in line with row 1. Make sure it is also centered in the middle of the board. Go to step 7 for the pin out and wiring diagram. Place the LM386 Amplifier at the very end, and also the resistors.
Case







To make the case, cut out 2 of each side pieces, and top and bottom pieces (the sizes depend on the use of your game and preferences) then on the top layer cardboard, cut out 4 holes big enough to fit your buttons. Then hot glue your buttons to the cardboard holes. Next, use a sewing pin to poke 4 holes beside the buttons (this will be for your 2 LEDs).
Then insert 2 of the same color LEDs (Red, Green, Blue, Yellow) into each of the 4 holes, with the longer probe facing the same direction. Then, twist the 2 opposite LED's opposite length probes together. Now you should have 2 probes from the LEDs. Repeat this step to all 4 (8 LEDs) sides.
Now, poke 4 holes for the RGB LED, and put it in. Next, connect the female end of female to male jumper wires to the buttons and the LEDs, note the + side and - side of the LEDs (otherwise it won't work). Now poke holes for your speaker on the top piece as shown above, after, hot glue your speaker on the edges to the cardboard.
Then hot glue the side cardboard pieces to the top cardboard piece, and pull the film off of the breadboard with the Pico, and stick it onto the bottom cardboard piece (opposite of the top). Lastly it's time for connecting the jumper wires to the breadboard.
Pins and Wiring


Buttons:
Button1 (Red) -> GP0
Button2 (Green) -> GP1
Button3 (Blue) -> GP2
Button4 (Yellow) -> GP3
LEDs:
Red1 -> GP4 -> 100Ω -> GND
Red2 -> GP4 -> 100Ω -> GND
Green1 -> GP5 -> 100Ω -> GND
Green2 -> GP5 -> 100Ω -> GND
Blue1 -> GP6 -> 68Ω -> GND
Blue2 -> GP6 -> 68Ω -> GND
Yellow1 -> GP7 -> 100Ω -> GND
Yellow2 -> GP7 -> 100Ω -> GND
RGB LED:
Red -> GP12 -> 100Ω -> GND
Green -> GP13 -> 100Ω -> GND
Blue -> GP14 -> 68Ω -> GND
Speaker:
GP11 -> LM386 Amplifier -> Speaker +
Speaker (-) -> GND
!!! FALIURE TO USE PROPER WIRING AND RESISTORS WILL LEAD TO DAMAGING YOUR PICO !!! (I had to buy a new one after burning my current one form pulling too much current :( ... )
P.S. You will see pin # and description on the Pico's backside. It’s a bit messy wiring I have there, sorry :(
Testing


After hot gluing the bottom piece, we have now successfully finished the project! Now we are going to test a game to see if it works.
I will be running the Pico off of 3 AA batteries via VSYS and GND, but you can also cut a hole in the cardboard and pass a cable through and run it off of a < or = 5v and lower than 1.5 amp power supply (your board will fry if you use > 5v or 1.5 amps).
Red is to chose solo game mode, try that. If you view in Thonny, you can see your options, and game progress on the outputs terminal. You should also hear feedback from the 8 ohm speaker driven by the LM386 Audio Amplifier, such as fanfare, and sound effects when you click the buttons. The lights will also flash Red, green, blue, and yellow, don’t forget the RGB LED! There are 40 total levels, and patterns each restart are different (random).
P.S. If you want to make this permanent, you can instead solder the wires to the Pico, and 3D print a case and hot glue all the items. I used cardboard to make this project more accessible to everyone (without soldering skills or soldering iron and 3D printer).