POiNG! - Arduino Arcade Game!
by hausofpayne17 in Circuits > Arduino
938 Views, 1 Favorites, 0 Comments
POiNG! - Arduino Arcade Game!
We'll be building a PONG-style arcade game that uses parts from the "The Most Complete Starter Kit UNO R3 Project" kit from Elegoo Inc.
Full Disclosure - Most of the parts supplied for this Instructable were provided to the author by Elegoo Inc.
I've wanted to build a project using an LED Matrix module. The basic 8x8 LED display requires the use of additional shift registers to be able to address the individual LEDs in the matrix. Instead, this project uses the MAX7219 8x8 LED module. It's a very easy module to use.
I would suggest that due to the large number of wiring connections on this project, it would be considered an INTERMEDIATE level Instructable.
Let's get started!
Supplies
Elegoo Starter Kit Parts Used (https://rebrand.ly/dvjb3w8)
- UNO R3 Microcontroller
- MAX7219 8x8 LED Module
- LCD 16x2 Display Module
- 10K Trim Potentiometer and knob
- Dupont Wires
- 220R Resistor
- Passive Piezo Buzzer
- Power Supply Module
- 9V 1A Adapter - needed because the UNO cannot supply sufficient current for the 8x8 LED Module
- Breadboard
Extra Parts Needed
2 x 10K Linear Potentiometer - inexpensive and widely available on eBay, AliExpress, Banggood etc.
Wiring Up the Circuit
Wire up the circuit as per the wiring diagram. Take your time. There are A LOT of connections required for the two displays.
Notice in the photo of the circuit that the power module is attached to the left side of the breadboard and the 9V 1A DC Adapter is plugged into the power module so that sufficient current is supplied to the LED matrix. There is NO connection between the 5V pin on the UNO and the breadboard. BUT, the GND pin on the UNO is connected to GND on the breadboard.
Double and triple-check your work.
Arduino Code
This instructable assumes that you already know how to program in Arduino.
Download the attached Arduino sketch. Make sure you've added in the LedControl library to your Arduino libraries. I used the version by Eberhard Fahle. Just search for MAX7219 in the Manage Libraries browser and you'll find and install it.
Make sure the pitches.h file is in your sketch's folder. It's used for playing the sounds in the game.
A bit about timing.
As the delay() command fully pauses the execution of your sketch when it runs, we instead look for elapsed time periods to occur when we want to execute animation-related parts of the sketch. We look for a preset amount of time to pass before we execute parts of the sketch such as updating the location of the ball on the display.
More significantly, the delay() command is really only executed in the loop() method. It typically does not execute as expected in other methods. So all animation-related timing is done in the loop() method.
Example:
We define some 'long' type variables and a couple of booleans and then set them at the end of setup().
bThresh = 80; // the time in milliseconds between ball updates
ballTime = millis();// set to the current system time
bon = false; // is the ball LED on or off
ballReturn = false; // are we returning a ball after a paddle hit?
In loop() for drawing the ball we have:
if ((millis() - ballTime > bThresh) && bon == false) {// if the ball is OFF and enough time has passed
ballOn();// turn on the ball LED
bon = true; // the ball is now ON
ballTime = millis(); // reset the ballTime to the current time
}
if ((millis() - ballTime > bThresh) && bon == true) { // if the ball is ON and enough time has passed
ballOff(); // turn off the ball LED
bon = false; // the ball is now OFF
ballTime = millis(); reset the ballTIme to the current time
}
There are many ways to make this game. These are just my preferences.
The sketch is fully documented so I invite you to read the code to see how it works.
Check, compile and upload your code.
Enjoy playing your game!
Conclusion
My thanks go to Elegoo Inc for providing the starter kit used in this project. It's a kit with a large variety of parts and modules that will get you well into the Arduino Maker world.
Now Go and Make Something Wonderful!