Esplora TFT Pong

This sketch is a very basic implementation of pong for the TFT screen with an Arduino Esplora.

This version of the game creates a rectangular platform that can move in two directions, and a ball that bounces against the edges of the screen as well as the movable platform. The slider on the Esplora controls the speed of the ball bouncing.

The example demonstrates collision detection between objects on the screen, as well as how to quickly update images without erasing the entire screen every loop()

Hardware Required

Arduino Esplora

Arduino TFT screen

Circuit

Attach the TFT screen to the socket on your Esplora, with the label "SD Card" facing up.

Code

To use the screen you must first include the SPI and TFT libraries. Don't forget to include the Esplora library as well.

moveBall() will update the ball's position, erase its previous location, and draw it in the new spot. It will also check to make sure it does not go off the screen, reversing direction when it hits the sides. This also calls a second custom function named inPaddle() which checks for intersections of the ball and paddle.

This example for the Esplora with an Arduino TFT screen reads
the value of the joystick to move a rectangular platform
on the x and y axes. The platform can intersect with a ball
causing it to bounce. The Esplora's slider adjusts the speed
of the ball.

This example code is in the public domain.

Created by Tom Igoe December 2012
Modified 15 April 2013 by Scott Fitzgerald