Intro: Atari-Style Game With an Arduino Controller
For this project, we will be making a very simple game modeled after the Atari game "Space Invaders". This game will mostly be coded in Processing, but will utilize an Arduino button and joystick to control the ship.
Everything in this project was done by hand using as few libraries as possible and thus the functionality is very limited and rudimentary; however I plan to come back to this project at a later date to update it with much nicer graphics and more functionality. For now, consider this project more of a proof-of-concept for Arduino-to-Processing real-time serial communication.
Step 1: Setup the Hardware
1. Connect a button to your Arduino using a breadboard, a resistor, and several wires
a) Place the button so that two prongs are on each side of the gap in your breadboard
b) Connect the top left button prong to the red power rail on your breadboard with a wire
c) Connect the bottom left button prong to the blue power rail on your breadboard using a 220 Ohm resistor
d) Lastly connect the bottom right button prong to your Arduino at digital input pin 12
2. Connect the joystick to your Arduino using the breadboard
a) Connect the ground (GND) pin on your Joystick to the blue grounding rail of your breadboard
b) Connect the power (+5V) pin on your Joystick to the red power rail of your breadboard
c) Connect the x-axis (VRX) pin on your Joystick to the Arduino at analog input pin A0 either directly or via the breadboard
d) Connect the y-axis (VRY) pin on your Joystick to the Arduino at analog input pin A1 either directly or via the breadboard
e) You do not need to connect the switch (SW) pin on your Joystick to the Arduino unless you plan to use the Joystick as a button.
3. Connect the Arduino to your computer using the USB adapter cable
Step 2: Setup the Code
1. Upload the provided code (Atari_Style_Gaming.ino) to your Arduino
a) The provided code simply reads in joystick movement and translates it into a directional command
2. Open Processing and import/open the provided code (All .pde files)
a) The provided Processing code is designed to allow for the user to move the ship with the joystick and shoot bullets with a button press
b) This code was written mostly as a proof of concept and to help work out the bugs in dealing with real-time Serial communication between Processing and the Arduino, but also for a fun project
3. Run the Processing code
a) The most common error I encountered was the erratic nature of signals read from the joystick. The fluctuations would change every time I uploaded the code to my Arduino and so would the neutral/resting joystick values. In the end I decided to sacrifice some sensitivity and use of variables and hardcoded values outside the range of the fluctuations. I left the previous code in, but commented out, in case anyone wants to play around with it.