For my project I wanted to develop a two-player game using a 8x8 LED matrix. The game begins with 2 lights, 1 red and 1 green (for each player) that show up on the matrix. They start cycling around the matrix and the goal of the game is to press the button when the light is in front of your button. The game is played first to three with the score indicated on the matrix. If someone misses, then their light starts moving faster and the other persons light starts moving slower. This is to prevent people from just pressing the button continuously and hoping to get lucky and score a point.
General view | Video | |
For this project, I used a bicolor 8x8 LED matrix controlled by HT16K33 driver via I2C interface and a microcontroller EFM32ZG108F32 from Silicon Labs. It has a battery holder that holds 4xAA batteries that power the project. A voltage converter is used to lower to voltage from 5V down to 3.3V needed for the microcontroller. It turned out that even if HT16K33 driver is rated for a 5V operation, it works fine being powered from 3.3V
Schematic | Assembly | |
This project was developed in Keil using the C programming language. The beginning of the code is used to set up the display of the matrix to indicate on which side the respective light needs to be caught. This is provided by the ">" and "<" shaped symbols as shown above. Then 1 red and 1 green dot on one of the outher matrix edges is turn on at a pseudo random position, but symmetric with respect to the matrix.
The dots then start to loop in the clockwise direction around the square In the loop there are some flags set up that are raised whenever someone presses a button. These flags are used for two things: to change the speed of the lights if someone misses, or for the moment when someone catches their light on their side. There is a function that checks an RTC interrupt for each button press and raises the flags.
When someone does not catch the light in front of their button then a flag is raised that stops both lights, so the users can clearly see if the light is caught or not. After a 2 second delay the game resumes and ithe light of the person who missed starts to loop faster, and the opponents light is slower.
When someone catches the light at the right position a flag is raised and a point is given to that player, which is indicated on the matrix with an orange LED lighting up (orange color is composed by turninng both red and green LEDs of the dot). Whenever a point is scored the speed is reset so both lights go at the same speed and they start from a pseudo random position again.
The game is repeated until someone scores 3 points. That is when the recursive Pulse() method is called to signal that a player has won the game, which is just a winning animation for the game. Then the display is set the same as it was at the beginning and all the speeds are set to default for the second round or for someone else to play.
While doing this project I found myself struggling with the microcontroller and the C language, since I did not have much knowledge on these things before. I felt like I could not do anything the first few weeks and I had trouble starting the project. Luckily Sergei was here to help me with all of the issues I had, and I got a much better understanding of implementing code with microcontrollers. Overall it was a fun experience to design my project and see it working at the end of the semester.
Last modified:Mon, Jan 23, 2023.