8×8 LED matrix – Atari Breakout inspired Arduino game

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.

Features

  • 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

middle
Ball hits paddle in the middle

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.

sideL
Ball hits paddle on left
sideR
Ball hits paddle on 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. 

endL
Ball hits comes from the left and hits the left side of the paddle
endR
Ball hits comes from the right and hits the right side of the paddle

It is only possible to hit all the bricks by combining the different ways the ball can bounce.

Parts

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)
  • wires

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

Pins used:

  • 9: L button
  • 8: R button
  • 7: Action button
  • A4: I²C D (data)
  • A5: I²C C (clock)
  • 5V power
  • GND

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 🙂

8x8 led matrix arduino game photo

8x8 led matrix arduino game drawing
Drawing of the connections (the LED matrix on this illustration is a bit smaller than the model I am using).
8x8 led matrix arduino game schematics
Schematics

Source code

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.

Files:

  • 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.

Libraries

In addition to the source code you also need the Adafruit Backpack Library and the Adafruit GFX Library installed.

Next Moves

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?

Notes

For information about how to install the backpack to the LED matrix, and how to install the needed libraries, checkout Adafruits own guide here.


Posted

in

,

by