#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ILI9341.h> // Hardware-specific library
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
#define TFT_WIDTH 240
#define TFT_HEIGHT 320
#define BALL_RADIUS 5
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Ball properties
int redBallX, redBallY;
int greenBallX, greenBallY;
int redBallSpeed = 1; // Adjust speed as needed
int greenBallSpeed = 1; // Adjust speed as needed
void setup() {
tft.begin();
tft.setRotation(3); // Adjust the display orientation if needed
// Set initial positions for the balls
redBallX = TFT_WIDTH / 2;
redBallY = TFT_HEIGHT / 2;
greenBallX = TFT_WIDTH / 2;
greenBallY = TFT_HEIGHT / 2;
// Clear the screen and set the background color
tft.fillScreen(ILI9341_BLACK);
tft.fillRect(0, 0, TFT_WIDTH, TFT_HEIGHT, ILI9341_BLACK);
// Add text at the bottom of the screen
tft.setTextSize(2);
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(5, TFT_HEIGHT - 25);
tft.println("by arvind patil 28/7/23");
}
void loop() {
// Update the positions of the balls
redBallY += redBallSpeed;
greenBallX += greenBallSpeed;
// Check for collision with screen boundaries and reverse direction
if (redBallY - BALL_RADIUS < 0 || redBallY + BALL_RADIUS >= TFT_HEIGHT) {
redBallSpeed *= -1;
}
if (greenBallX - BALL_RADIUS < 0 || greenBallX + BALL_RADIUS >= TFT_WIDTH) {
greenBallSpeed *= -1;
}
// Clear previous ball positions
tft.fillCircle(redBallX, redBallY - redBallSpeed, BALL_RADIUS, ILI9341_BLACK);
tft.fillCircle(greenBallX - greenBallSpeed, greenBallY, BALL_RADIUS, ILI9341_BLACK);
// Draw the balls at their new positions
tft.fillCircle(redBallX, redBallY, BALL_RADIUS, ILI9341_RED);
tft.fillCircle(greenBallX, greenBallY, BALL_RADIUS, ILI9341_GREEN);
// Add a slight delay to control the animation speed
delay(10);
}