Introduction: Arduino LCD Game With Flashing LEDs

There's lots that can be done with microcontrollers and integrated circuit chips. Using these two in conjuntion with an LCD display, I managed to create an infinite runner with flashing LEDs to simulate the real feel of an arcade. This circuit was made as the final project for my computer engineering class where we were given free reign to make whatever we wanted as long as it served a clear purpose and would demontrate our learning of at least two of the major topics covered. When we were shown examples of what the previous classes had made I saw one that was basically a videogame that was being displayed on an LCD and powered by an Arduino and that gave me the idea to do something similar to that. I didn't know what to do include for the second topic and was given the suggestion to put flashing LEDs around the display to recreate the flashing lights of an arcade cabinet. I did some research on some similar projects made both physically and digitally and also some research on how to program for a LCD display. There weren't any projects I could find that combined both of the ideas I had so I looked at seperate projects and tried to find ways I could fit them both on the same space.

Supplies

  • A 555 timer
  • Eight multicoloured LEDs
  • A 1K Ohm resistor
  • A 400K Ohm resistor
  • Two 330 Ohm resistors
  • A 220 Ohm resistor
  • An Arduino Uno
  • A 16x2 LCD display
  • Two pushbuttons
  • A 1 μF capacitor
  • A breadboard
  • Wires

Step 1: Setting Up the LCD

The first thing I set up was the LCD. I knew I wanted the LCD to be surrounded by LEDs but a lot of the top was used for ports and the display took up too much space for me to put them at the bottom so I kept them to the sides. I conneced the 5V and gorund pins of the Arduino to the power rails and connected the bottom two power rails with the top two using wires. I then connected the different LCD pins to the Arduino and the power rails. The power and LED anode pins were connected to power rail with the anode pin specifically being connected with the 220 Ohm resistor, the ground and LED cathode pins were connected to the ground rail, and the rest to the Arduino. The fuction of the Vo pin is to control contrast which in this case lets us control the different animations that our character will undergo when he makes specific movements. The RS pin is used for selecting whether we will send commands or data to the LCD. For example if the RS pin is set on zero volts, then we are sending commands to the LCD which in our case will be jump or start game. Thre RW pin is the read write pin which tells the LCD whether to read or write information from and to the Arduino. The E pin is the enable pin and it's used to enable the rest of the input pins, D0-D7. Of these 8 pins we only need to use four. I chose to use D4-D7 but you could use whichever ones you want as long as you change the code accordingly. I connected the Vo pin to pin 12 on the arduino, RS to 11, RW to 10, E to 9, D4 to 6, D5 to 5 D6 to 4, and D7 to 3. Finally came the buttons which connect to pins 1 and 2 on the Arduino. These pins serve as the manual play and autoplay features with the button connecting to pin 1 allowing the game to play itself as long as it's held down and the button connecting to pin 2 allowing the player to control the character's jumps themselves

Step 2: Programming the Arduino

This was the first time I was coding for an LCD display so my code might be a bit more rudimentary than other's. I did was define which pins served what functions as so I defined pin 2 as the standard button, pin 1 as autoplay, 10 as read/write and 12 as the contrast. Then I started defining what each of the character and terrain sprites should be. It could get a bit confusing knowing which line of text is supposed to represent what so I left comments to the side of some of them that should be visible in the link. Then came actually creating the sprites. I used binary to create the sprites. There are 32 blocks that make up an LCD display and each block has 45 pixels. Using binary I created sprites for Guy (our protagonist) and the different types of terrain, ground and overhangs by putting 1 in pixels I wanted filled and 0 in pixels I wanted empty. I created 2 sprites for his waking animations, 2 for his jump, and 3 for the ground. Then came the coding for the score. I set it up so that if the amount of bytes is under 9, there would be 1 digit, if the amount of bytes is under 99, there would be two digits and so on and so forth until the score hits 9999 where it maxes out. Then we can finally start the void setup. Essentially, pressing the button enters a state called 'falling' which acts as the jump. If holding down the auto button, Guy will be put into that state right before he hits a solid block (i=0) but if pressing down the manual button he can enter that state whenever and will jump at the player's will. The manual button has a built in interrupt however that cancels the state and will cause him to fall back down. The load screen came next where I had it set so that the initial starting screen had text that displayed Start Game using the lcd.print command as well as our main character flashing. The screen stays like that until it registers a button press from the pin 2 button where the game will then start. Once it's pressed it activates the initialize graphics line that causes the animations like Guy walking and jumping and it also resets the score back to zero, but only if the playing status is off. Hitting a wall will cause the playing status to deactivate, causing the animations to stop and the message "press start" to pop up again, all of which gets explained in the last part of code

Step 3: The Flashing LEDs

The last step in this process is to finally set up the lights. For this you'll want a 555 timer put relatively far away from the other components to have as much space as possible. First connect the chip to the power power and ground rails using wires. You will also want to supply power to reset as well. Place the 1k Ohm resistor from power to the breadboard and place the 400k Ohm resistor a little in front of that while making sure that the rings of both resisors are away from the power source. Place a wire in between the two resistors and put that in the discharge. Put two wires on the ring side 400k resistor so that one leads to threshold while the other leads to trigger. Place a capacitor so that the two wires are between it and the resistor and so the positive terminal is in line with the wires and connect a wire from the negative terminal to the negative rail. Place a wire in front of the output and have it lead to a 330 Ohm resistor and another wire which goes back to the top half of the breadboard and then reaches the other 330 Ohm resistor. Connect the ringed side of the resistor to the cathodes for the LEDs on the top half and anodes for the LEDs on the bottom. That should be it for the LEDs and when you activate your circuit the game should turn on and the lights should start flashing