#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define TFT_CS 9
#define TFT_DC 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define WIDTH 320
#define HEIGHT 240
int truckX = 100; // Initial X position of the truck
void setup(void) {
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
}
void loop() {
tft.fillScreen(ILI9341_BLACK); // Clear the screen
drawTruck(truckX, 120); // Draw the truck at the current position
truckX -= 50; // Move the truck to the right
if (truckX > WIDTH) { // Reset position if the truck moves off screen
truckX = 200;
}
delay(1); // Delay to control the speed of the truck
}
void drawTruck(int x, int y) {
// Draw the body of the truck
tft.fillRect(x, y, 200, 40, ILI9341_RED); // Main body
tft.fillRect(x + 40, y - 20, 80, 40, ILI9341_RED); // Top part
// Draw the windows
tft.fillCircle(x + 60, y, 15, ILI9341_WHITE); // Left window
tft.fillRect(x + 120, y - 10, 40, 20, ILI9341_CYAN); // Right window
// Draw the wheels
tft.fillCircle(x + 30, y + 40, 20, ILI9341_BLACK); // Left wheel
tft.fillCircle(x + 170, y + 40, 20, ILI9341_BLACK); // Right wheel
tft.fillCircle(x + 30, y + 50, 15, ILI9341_YELLOW); // Left wheel hub
tft.fillCircle(x + 170, y + 50, 15, ILI9341_YELLOW); // Right wheel hub
// Draw the triangle (assuming it's part of the truck design)
tft.fillTriangle(x + 120, y - 10, x + 160, y - 10, x + 140, y - 50, ILI9341_CYAN);
}