Chapter 5 Pong Game

We have experienced single-player game snake before. Now, let’s use ESP32 board to play classic two-player pong game. You will experience both 2D and 3D version.

Project 5.1 Pong Game

First, let’s experience the 2D version game.

Component List

ESP32-WROVER x1

Chapter01_00

GPIO Extension Board x1

Chapter01_01

Breadboard x1

Chapter01_02

Rotary potentiometer x2

Chapter09_00

Jumper M/M x6

Chapter01_05

Circuit

Use A0, A3 ports on ESP32 board to detect the voltage of rotary potentiometers.

Schematic diagram

Chapter05_00

Hardware connection

Chapter05_01

Sketch

Sketch Pong_Game

Use Processing to open Pong_Game and click Run. If the connection succeeds, the follow will be shown:

../../../_images/Chapter05_021.png

Now you can try to turn the potentiometer to control the movement of paddle without ball. Press space bar to start the game:

../../../_images/Chapter05_031.png

Use potentiometer to control the movement of paddle to block the ball back. The game rules are the same as classic pong game:

../../../_images/Chapter05_041.png

The game will be over when one side reachs three points. Pressing the space bar can restart the game:

../../../_images/Chapter05_05.png

Additionally, you can restart the game by pressing the space bar at any time.

Project 5.2 Pong Game 3D

Now, let’s experience the 3D version game.

Component list

The same as last section.

Circuit

The same as last section.

Sketch

Sketch Pong_Game_3D

Use Processing to open Pong_Game_3D.pde and click Run. If the connection succeeds, the follow will be shown:

../../../_images/Chapter05_061.png

Now you can try to turn the potentiometer to control the movement of paddle without ball. Press space bar to start the game:

../../../_images/Chapter05_071.png

Use potentiometer to control the movement of paddle to block the ball back. The game rules are the same as classic pong game:

../../../_images/Chapter05_08.png

The rest operation is the same as the 2D version.