I was motivated to create this mini-game because of my interest in memory games, like Simon Says and pattern and sorting games. I wanted to make an engaging way for people to test and build their memory skills. I planned to keep the design compact so it can be used anywhere and can be shared among friends in group settings!
BreadboardWiring
In order to start the building the circuit for this mini-game, I first created system and power block diagrams to plan out which pins I would use and power sources. After planning this out, I could then began the wiring for my game. An outline of the steps I followed to build my project's hardware follows:
First, I placed my Pocket Beagle on the breadboard and started wiring the buttons that correspond to each LED, the start button, and the next round button.
In order to power the buttons, I connected the 3.3 V power supply from pin P1_13 to the positive rail of the breadboard, and ground from pin P1_15 to the negative rail. In between the 3.3 V and the button, I added a connection to a GPIO pin and a 4.7 kOhm resistor, and the other pin of the button was connected to ground. Each of the color buttons correspond and match the order of the LEDs that light up. The start button was powered using pin P2_24 and grounded using pin P2_21.
For each of the LEDs, I powered them using the GPIO pin. I connected the GPIO pin to the anode and the cathode to ground, which powered the negative rail of the LED breadboard.
Finally, for the 7-segment display, I powered it with 3.3 V. I connected the 3.3 V source to the positive rail of a separate breadboard and ground to the negative rail. I added jumper wires between the sections of the breadboard and pull up resistors for the last 2 pins of the display. The pull up resistors were then wires to the I2C1 connections (P2_9 – SCL and P2_11 – SDA).
Codingthe Mini-Game
Once all the wiring for the breadboard was set up, I worked on coding the simon says game. I first tested all my hardware using the class files : button_test.py, led.py, and ht16k33.py. Then, I created my project file game.py. This file runs code from 3 separate classes: Button(), LED(), and HT16K33(). My project also contains a run script that, using cron, allows the code to run automatically on boot.
For the LED() class, I built off the led.py file in order to illuminate my led lights. First, I used a random number generator that gives a number 1-4, which corresponds to each color light. There includes a counter which determines what round of the game the user is on, and in each round, the cound appends a new random number to the light up list. Then, the code runs through the order of lights, illuminating the respective led.
For the Button() class, I built off the button_test.py file in order to process when the button is pressed. First, I updated the code to return a number when a button is pressed and then it should check which specific GPIO pin is being utilized. After it determines which specific button was being pressed, it returns a number for each of the different colors or type of button - start or next round. The game won't start unless the code detects the start button being held down, and further the game won't progress unless the next round button is clicked. Additionally, I imported the LED() class into the button file in order to illuminate the respective led when the button was clicked, to ensure the user clicked the button properly.
Finally, for the HT16K33() class, I implemented the kt16k33.py file from class in order to display text on the 7-segment display. If the code receives input that the game has been started, then the display will light up with "Play", and if the user loses, the display will show "Lost" and then the score.
All these classes were combined and implemented in the game.py file. More information on the code can be seen later in this documentation and on my github respository: ENGI301.
Using the DeviceIn order to play the mini-game:
1. Press and hold the black button under the LED lights until the display lights up with "Play". Shortly, the game will start.
2. A random light will illuminate and the user should match the light to the corresponding button, ensuring it was clicked if the led lights up on the other breadboard.
3. The user presses the black submit button at the top of the color buttons and waits for the next round. The next round will display the same colors as before, with one additional random color.
4. The user will keep going until they mess up, to the which the display will show "Lost" and the score right after.
A video demonstration can be seen here:
Future WorkIn the future, I want to implement a speaker that can play a corresponding sound for each of the LEDs. It would add a musical component to the game that could make it more entertaining and fun to play for a longer time. I added a buzzer to the game currently, but the frequency emitted from the buzzer wasn't a pleasant sound so I opted to keep it out of the game. Additionally, I want to create a small box that could house each of the breadboards in order to hide all the wiring for the buttons, leds, and display screen. It could make the game more portable and less likely to fall apart when moving around. Finally, after playing the game numerous times, I wanted to add a feature that speeds the lights up after each round to make it harder to get further in the game.
AcknowledgementsI would like to give a huge thanks to Professor Erik Welsh for all his help throughout the course of this project!
Comments