In this post you will find details on how to start making your own 8×8 LED matrix Arduino breakout game.
The gameplay is simple but still entertaining because of the different ways the ball bounces when hitting the paddle.
- Three buttons:
- L: move paddle left.
- R: move paddle right.
- Action: release the ball
- Increases speed of game for each game won (max. three times).
- Blinking sad and happy smiley for when you lose or win the game
- Ball bounce in the different ways depending on where on the paddle it hits:
In the middle: ball bounces directly upwards
On either end of the paddle: ball continues in same x-direction but the y-direction changes. Exception: If the balls x-direction was 0 is will be changed to either -1 if it hits paddle on the left and 1 if it hits the paddle on the right.
On either side of the paddle (not directly over the paddle): ball bounces back to the direction it came from. Changes both the x- and y-direction.
It is only possible to hit all the bricks by combining the different ways the ball can bounce.
This is mainly a software project and thus only require a few parts.
- 1 x Arduino Uno
- 1 x Adafruit Small 1.2″ 8×8 LED Matrix w/I2C Backpack – Pure Green
- 3 x 6 mm tactile switches (buttons)
- 3 x 10 kΩ resistors
- Solderless Breadboard (830 point)
You can also use a LED matrix without the backpack, but this will require additional code and connections. I will try to make a post with inspiration on how to do this at a later time – but it is a more advanced project.
Circuit and schematics
- 9: L button
- 8: R button
- 7: Action button
- A4: I²C D (data)
- A5: I²C C (clock)
- 5V power
Bellow is photo, illustration and schematics of the connections and circuit. Hopefully this will be enough for you to assemble it correctly. Do not hesitate to leave a comment if you need additional information 🙂
The code for this project can be downloaded here on GitHub.
I use a 8×8 char array to keep track of where the different objects of the game is positioned at a given time.
The reDraw function in game.ino then uses this char array to visualize this using the correct pixels on the led matrix.
- game.ino: this is the Arduino sketch that starts the program. It holds the loop function which controls the game according to the current game state.
- Breakout.h + Breakout.cpp: This class holds most of the game rules and reactions on different player input.
- Ball.h + Ball.cpp: Hold information on a balls position and how the ball bounces in different directions.
- Paddle.h + Paddle.cpp: Determines how the paddle moves left and right in addition to store where the paddle is located and how wide it is (size).
- Config.h: Defines the Arduino pins used, start values of different objects and enums in the code.
- Faces.h: Layout matrixes of the sad and happy faces used for game lost and game won.
The source code is released under the GNU GPLv3 license.
Additions you could try to implement:
- Make the game harder by decreasing the size of the paddle after a certain number of wins.
- Add a scoring system to the game.
- Make it possible to move the paddle before sending the ball on its way.
- Bring the prototype to the next level and make some kind of case for the game.
- Add sound effects
- Tired of playing the same game over and over? Why not make a full-blown 8×8 LED Matrix handheld gaming console? Snake, pong, space invaders, car game, Simon Says, Tetris or maybe even an adventure maze game?
For information about how to install the backpack to the LED matrix, and how to install the needed libraries, checkout Adafruits own guide here.