Ping-Pong Game

by 731458 in Circuits > Arduino

390 Views, 2 Favorites, 0 Comments

Ping-Pong Game

download.png

Hello, my name is Sejal and for my final evaluation, I am creating a ping pong game. It is a two player game. You will be using the push buttons to move the paddle and try to score a point on the other person. It is just a fun game to play with friends. Let's talk about the materials to get started on this products.


I have included the game code down below

Supplies

Research

I wanted to make something using an LCD because I thought it would be cool to do something different than what I would normally do. Since I do have some coding experience in c++, I have done other projects but I haven't used a LCD before so I wanted to do something other than my comfort zone. I was going through a website I really like for Arduino and came across a ping pong game. After seeing this, I had some inspiration on what I wanted to do and I tried to make my own design.

Wiring

Screen Shot 2023-01-24 at 10.46.03 AM.png

This is how the wiring should look on TinkerCad.

First we are going to wire up the circuit to the Arduino.

LCD:

RS - pin 12

E - pin 11

DB4 - pin 5

DB5 - pin 4

DB6 - pin 3

DB7 - pin 2

LED:

LED1 - pin 0

LED2 - pin 1

Push button:

start - pin 13

paddle 1 up - pin 6

paddle 1 down - pin 7

paddle 2 up - pin 8

paddle 2 down - pin 9


For the potentiometer instead of connecting it to the Arduino, we are connecting it to the LCD and we are connecting it to pin VO.


Code

Screen Shot 2023-01-25 at 8.44.27 AM.png

Before we get started on the void setup, we are going to insert the LiquidCrystal library and also identify the pins that get connected to the Arduino from the LCD. We then define what other pins are connected to the Arduino while making the variable names. As for the arrays, we are making arrays for the paddles and the ball. This is to make the paddle and ball and to also hold the values. For the next part we are going to set everything to 0 and also identify the direction as left so that the ball will always start going to the left.

Code

Screen Shot 2023-01-25 at 8.52.35 AM.png

For the void setup, we are going to start by defining which one is input and which one is output. After that we are going to print text on the LCD.

lcd.begin - begins lcd communication

lcd.clear - clears the lcd screen

lcd.setCursor - sets cursor

lcd.print - prints text

Code

Screen Shot 2023-01-25 at 8.58.12 AM.png
Screen Shot 2023-01-25 at 8.58.49 AM.png
Screen Shot 2023-01-25 at 8.59.25 AM.png
Screen Shot 2023-01-25 at 8.59.50 AM.png
Screen Shot 2023-01-25 at 9.00.22 AM.png
Screen Shot 2023-01-25 at 9.01.24 AM.png

On to the void loop.

In the void loop we are going to be making a lot of if statements and checking if the button has been pressed. This is where the main part of the game is made because of all the functions.

Code

Screen Shot 2023-01-25 at 9.15.54 AM.png
Screen Shot 2023-01-25 at 9.16.28 AM.png
Screen Shot 2023-01-25 at 9.17.02 AM.png
Screen Shot 2023-01-25 at 9.17.22 AM.png

This part is for the functions that are added in the void loop.


How to Play

How to play:

there is a push button on the side which is the start push button after pressing that there are four other push button, two on the left side and two on the right side. The first push button on each side(left side) is paddle up and when you press that the paddle goes up and the second push button on each side is paddle down and that is to move the paddles down. The target is to make the other person lose.


Real life video down below: