LCD Game for Final Project

by 733417 in Circuits > Arduino

129 Views, 1 Favorites, 0 Comments

LCD Game for Final Project

IMG_3165.jpg
image_2024-01-22_090226583.png

The one on the left is what my Project looks in Real Life and on the right is how it looks on Tinkercad.

Supplies

All the supplies you need to make this is:


  1. (1)Breadboard
  2. (1)Arduino Uno
  3. (1) push button
  4. (2) LED's (Yellow and Green)
  5. (1) Buzzer
  6. (1) i2C LCD 16 x 2
  7. (2) 330 Ohms Resisters
  8. Wires

Adding Push Button to the Breadboard

image_2024-01-22_090000077.png

Step 1 would be adding the button so I can use it later to control person jumping in the game that will play on the LCD. what you need to do first add 1 button and connect the button to the Arduino digital pin 2. Then add in a wire from ground to the other side of the button.

Adding LEDs to the Breadboard

image_2024-01-22_090058316.png

For Step 2 you will need to add 2 LEDs, 1 Green and 1 Yellow so it can be used to indicate if the game is currently running or whether you need to "Press Start"(push the button) in order to start the Game again.

Adding Buzzer to the Breadboard

image_2024-01-22_090136456.png

In step 3 you will need to add a buzzer so that when you lose it will start buzzing and the LCD will tell you to "Press Start" In order to start the game again.

Adding LCD to Finish Building the Breadboard

image_2024-01-22_090214386.png

This is the last step in order to Finish Building the Breadboard where you would add the 16x2 i2c LCD display which will display the game that will be controlled by the push button.

Part 1 of Code

Part 1 of LCD Game.png

Libraries

#include <LiquidCrystal_I2C.h>

#include <Wire.h>

These lines include two libraries: LiquidCrystal_I2C and Wire. LiquidCrystal_I2C is commonly used for interfacing with LCD displays over I2C, and Wire is used for I2C communication.

Definitions(All the lines that have #define infront of them)

These are preprocessor macros that define constants. They are used to make the code more readable and to avoid using "magic numbers" in the code. For example, PIN_BUTTON is defined as 2, which makes the code more understandable than using the number 2 directly.

Variables

int YellowLED = 12, GreenLED = 13, buz = 4;

These are global variables. "YellowLED, GreenLED, and buz are assigned pin numbers for LEDs and a buzzer. This suggests that the project involves controlling LEDs and a buzzer using an Arduino.


Part 2 of Code

image_2024-01-22_092839403.png
image_2024-01-22_092904044.png

This piece of code sets up a 16x2 LCD display connected through I2C communication on the Arduino. It also defines two static arrays to store characters representing upper and lower parts of the game terrain. A boolean variable is initialized to keep track of whether a button has been pushed. The code introduces a function called initializeGraphics() that creates a series of graphical patterns using binary numbers. These patterns represent different poses of a character in the game, like running and jumping. The code ends by declaring an integer variable i, likely used for iterating through the graphical patterns in the later parts of the program. In simple terms, this code segment is preparing the visual elements needed for a game or animation to be displayed on the LCD screen.

Part 3 of Code

image_2024-01-22_092945399.png

In this part of the code, it's setting up a display for a game or animation. It creates custom characters for different sprites using the lcd.createChar() function, which makes it easier to draw these characters on the display. Then, it initializes arrays to represent the upper and lower parts of the game terrain as empty spaces. The second part defines a function called advanceTerrain that makes the terrain shift to the left in small steps. The function looks at each part of the terrain and decides whether to show an empty space, a solid block, or move a block left or right. This creates a scrolling effect, making it look like the game or animation is continuously moving forward. Overall, these steps help set up the visual elements of the game or animation on the display.

Part 4 of Code

image_2024-01-22_093023275.png
image_2024-01-22_093041611.png

This piece of code is like a manager for a simple game. It's in charge of drawing a car on the screen and handling its movement. The car has different poses or positions, and the function decides what the car should look like based on its current position. It checks if the car collides with the game terrain (the ground and obstacles) and updates the terrain accordingly. Additionally, it keeps track of the player's score and figures out how many digits the score has so that it can be displayed properly on the screen. The code is a part of a bigger program that likely involves a game where a car moves around, and the player's score is shown on the screen.

Part 5 of Code

image_2024-01-22_093131980.png
image_2024-01-22_093222182.png

This piece of code is like the artist's brushstroke on a canvas. It's responsible for showing things on a small screen. Imagine the screen is split into two parts, like upper and lower sections. The code manages the drawings on these parts. It does things like displaying a score at a particular spot and handling a button press. The button press is like a special event that the code pays attention to. The setup function at the end prepares everything before the drawings start. It's like setting up the colors and tools before an artist begins their work. So, in simple words, this code is about making things appear on a screen and getting ready for the action to begin.

Part 6 of Code

image_2024-01-22_093457903.png
image_2024-01-22_093531030.png
image_2024-01-22_093614199.png

This code is like the brain of a simple game on an Arduino. The game has a car that moves on a screen. The loop function does different things depending on whether the game is just starting or already in progress.

When the game is not running, it shows a blinking car or a message saying "Press Start" on the screen. If you press a button to start the game, it sets up everything for the game to begin.

When the game is running, the loop makes the car move forward and generates new obstacles on the screen. It also checks if you press the button to make the car jump. If the car hits an obstacle, the game ends, and lights and a buzzer might make noise to signal the end of the game.

In simple terms, the loop takes care of everything happening in the game - from starting it to making the car move and handling when the game ends.