กลับไปหน้ารวมไฟล์
oled-096-inch-display-pong-game-for-arduino-uno-r3-88a393-en.md

My project is about a pong game on an 0.96 oled display useing the arduino uno r3 and 2 side buttons to control it!

Retro Gaming in Miniature

The OLED Pong Mini-Game is a classic software engineering challenge minimized into the palm of your hand. By utilizing a high-contrast SSD1306 OLED screen and simple momentary buttons, you can recreate the high-speed physics of the 1970s arcade era. This project is a perfect introduction to Graphical Frame Buffering, I2C Communication, and Zero-Latency Input Handling.

Hardware Infrastructure & Wiring

  • Arduino UNO R3: The "Game Console." It handles all coordinate calculations, score tracking, and the I2C data bus.
  • OLED Display (0.96 inch): A 128x64 resolution monochrome screen. Because it’s an OLED, every pixel generates its own light, providing perfect blacks and sharp visuals.
    • SDA (A4) / SCL (A5): The standard I2C pins used for high-speed graphical data transfer.
  • Tactile Buttons (x2): The "Controller." One button is assigned to move the paddle UP, and the other for DOWN.
    • Internal Pull-Ups: The code uses INPUT_PULLUP for the buttons, meaning they are connected between the digital pins (D2/D3) and GND—no external resistors required!

Game Loop Logic and Physics

The software runs at a high frame rate (typically 30-60 FPS) to ensure smooth gameplay:

  1. Input Polling: The Arduino checks Pin 2 and Pin 3 every few milliseconds. If D2 is pressed, the paddle's Y-coordinate is decreased; if D3 is pressed, it is increased.
  2. Ball Vector Calculation: The "Ball" object has an X and Y position, plus vX and vY (velocity) variables. In every loop cycle, position = position + velocity.
  3. Collision Detection:
    • Walls: If ball Y < 0 or Y > 63, the vY vector is inverted (vY = -vY).
    • Paddles: The code checks if the ball's X/Y coordinates overlap the paddle's rectangle. If they do, vX is inverted, making the ball bounce back.
  4. Drawing Output: The Arduino sends the new coordinates of the ball, paddles, and score to the OLED via the I2C bus using the display.display() command.

Educational Value and Scalability

This project teaches the core foundations of Game Development—physics, rendering, and input. It demonstrates how to manage complex graphical updates over a slow I2C bus by only redrawing what changes. Once the basic Pong logic is perfected, you can expand this into more complex games like Brick Breaker, Snake, or a Side-Scrolling Platformer.

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

title: "Oled 0.96 inch display Pong Game for arduino uno r3!"
description: "OLED Display GND-GND VCC-5V A5-SCL A4-SDA UP Button gnd-gnd next pin to d2 DOWN Button gnd-gnd next pin to d3"
author: "kelly77"
category: "Gadgets, Games & Toys"
tags:
  - "game"
  - "easy"
views: 9914
likes: 4
price: 699
difficulty: "Easy"
components:
  - "1x Jumper wires (generic)"
  - "1x small buttons"
  - "1x 0.96 OLED display"
  - "1x Arduino UNO"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "12f51ee57886f779f3a2a1d0d5433ccf931cfa493f750e532e9893cfe6c24d80"
encryptedPayload: "U2FsdGVkX19DyYBwYyeM3JoQZIBJ4+lLwr0yc3ag7+K1crXOWsPvpFZhi/dFL/IAi7ydyjNCVCBY+PpW2OCg06ndyfqL87dt/Brk/An599B4FaSCotA+FPXeqQyCNsY10VK5L+c4KqgXvS3LZm5LtA=="
seoDescription: "Create a Pong Game on an OLED 0.96 inch display with Arduino Uno R3. Includes wiring for Buttons and OLED screen."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/oled-096-inch-display-pong-game-for-arduino-uno-r3-88a393_cover.jpg"
lang: "en"