#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI(); // Create a TFT_eSPI object
int x = 240; // Initial X position of cursor
int y = 160; // Initial Y position of cursor
void setup() {
tft.init(); // Initialize the display
tft.setRotation(1); // Rotate the display 90 degrees clockwise
tft.fillScreen(TFT_BLACK); // Fill the screen with black
}
void loop() {
int dx = analogRead(A0) - 512; // Read X-axis joystick value
int dy = analogRead(A1) - 512; // Read Y-axis joystick value
if (abs(dx) > 10) { // If joystick moved left/right
x += dx / 100; // Move cursor left/right
if (x < 0) x = 0; // Keep cursor within bounds
if (x > 479) x = 479;
}
if (abs(dy) > 10) { // If joystick moved up/down
y -= dy / 100; // Move cursor up/down (Y-axis inverted)
if (y < 0) y = 0; // Keep cursor within bounds
if (y > 319) y = 319;
}
tft.drawPixel(x, y, TFT_WHITE); // Draw cursor at new position
}