#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int ballX = 5;
int ballY = 5;
int moveAmount = 1;
void setup() {
Serial.begin(9600);
tft.begin();
// Setups for the tft
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setTextSize(1);
// Draw Dimentions of TTGO T-Display 135x240
tft.drawLine(0, 0, 135, 0, ILI9341_WHITE); // TOP
tft.drawLine(135, 0, 135, 240, ILI9341_WHITE); // RIGHT
tft.drawLine(0, 240, 135, 240, ILI9341_WHITE); // BOTTOM
tft.drawLine(0, 240, 0, 0, ILI9341_WHITE); // LEFT
}
void loop(void) {
/*
tft.fillCircle(5, 5, 2, ILI9341_RED); // Top Left
tft.fillCircle(130, 5, 2, ILI9341_RED); // Top Right
tft.fillCircle(130, 235, 2, ILI9341_RED); // Bottom Right
tft.fillCircle(5, 235, 2, ILI9341_RED); // Bottom Left
*/
/*
// Display values
tft.setCursor(10, 20);
tft.println("X Value: "+ String(ballX));
tft.setCursor(10, 30);
tft.println("Y Value: "+ String(ballY));
*/
// Draw the ball
tft.fillCircle(ballX, ballY, 2, ILI9341_WHITE);
delay(10);
// "Erase" the ball
tft.fillCircle(ballX, ballY, 2, ILI9341_BLACK);
// Move the ball right
if (ballX < 130 && ballY == 5){
ballX = ballX + moveAmount;
// Move the ball down
} else if (ballX == 130 && ballY < 235){
ballY = ballY + moveAmount;
// Move the ball left
} else if (ballX > 5 && ballY == 235){
ballX = ballX - moveAmount;
// Move the ball up
} else if (ballX == 5 && ballY > 5){
ballY = ballY - moveAmount;
} // END ball movements
}