กลับไปหน้ารวมไฟล์
arduino-uno-snake-game-22-tft-display-e6e0d1-en.md

Advanced SPI Color Graphics: Snake on 2.2" TFT

A 16x2 LCD is just sending bytes of letters. A massive 2.2" TFT Color Screen requires the Arduino to physically draw every single microscopic pixel independently. The Snake Game on 2.2" TFT Display requires programmers to execute the most demanding SPI logic ever created for the Uno, managing thousands of X/Y spatial Cartesian loops, redrawing rapidly growing green byte-arrays before the player's joystick action expires!

1306_oled_retro_game_display_1772681532057.png

The Adafruit_ILI9341 Engine

There are $320 \times 240$ pixels on this screen, totally $76,800$ individual dots!

  1. The Uno cannot store the image in RAM because it only holds $2,000$ dots total!
  2. You cannot use display.display() like an OLED. You must execute direct, absolute geometry painting!
  3. Erasing the Tail: As the massive Snake array moves, plotting a new green head is easy tft.fillRect(headX, headY, 10, 10, ILI9341_GREEN);.
  4. But the tail never disappears! You must explicitly tell the SPI bus to draw a black square exactly over the last index of the snake body array!
tft.fillRect(tailX[last], tailY[last], 10, 10, ILI9341_BLACK); // Erase the ghost image physics!

High-Speed Joypad Interrupts

Because pushing 76,000 pixels over 5 SPI wires takes nearly 150 milliseconds for a full screen clear, standard digitalRead() inputs become extremely sloppy and unresponsive.

  • The 2-Axis Joystick uses analog geometry analogRead(A0).
  • The loop() utilizes custom timing constraints:
if (analogRead(JoyY) > 800 && direction != DOWN) {
   direction = UP; // Execute immediately to prevent sluggish steering!
}
  • A massive Apple (ILI9341_RED) randomly mathematically jumps onto the screen. It validates against snakeX[] \ snakeY[] arrays, ensuring it does not magically spawn physically inside the snake's body!

SPI Color Console Parts

  • Arduino Uno/Mega (Mega is wildly preferred. A Mega runs Snake flawlessly, allowing massive array expansion. An Uno will run out of RAM around length 80, instantly randomly crashing the entire game in a memory overflow!).
  • 2.2" or 2.8" SPI TFT Display (ILI9341 Controller Chip).
  • Dual Axis Potentiometer Joystick or a standard 4-Button D-Pad configuration.
  • (Note: Ensure logic-level shifting! Most TFT screens require exactly 3.3V on their SPI pins, not 5V!)

ข้อมูล Frontmatter ดั้งเดิม

title: "Arduino Uno - Snake Game - 2.2\" TFT Display"
description: "Color matrix engineering! Discard the painful restrictions of I2C text screens by embracing massive SPI color protocols, mapping thousands of pixels simultaneously to an ILI9341 display in this vivid arcade replica."
category: "Gaming & Entertainment"
difficulty: "Advanced"