This is an old revision of the document!
Dual-Controller OLED Tic-Tac-Toe is a portable handheld gaming device specifically designed for two players. This project brings the classic game of Tic-Tac-Toe to a custom electronic platform built around an Arduino Uno board.
Project Goals:
The project consists of several integrated subsystems that handle input processing, game logic execution, and visual feedback:
Hardware Components:
Software Components:
This section describes the electronic components used to build the gaming console and their interconnections.
| Component | Quantity | Description / Role |
|---|---|---|
| Arduino Uno R3 | 1 | Central Processing Unit (ATmega328P microcontroller). |
| OLED Display (SSD1306) | 1 | 128×64 pixel monochrome screen, I2C interface, for rendering the game grid. |
| Joystick KY-023 | 2 | Analog modules for cursor control (X/Y) and selection (integrated button). |
| Passive Buzzer KY-006 | 1 | Provides audio feedback (PWM tones) for moves, errors, and victory. |
| Breadboard (400 points) | 1 | Platform for solderless electrical connections. |
| Dupont Wires | 1 set | Interconnecting wires for the components. |
The firmware is designed using a Finite State Machine (FSM) approach to manage game transitions, coupled with real-time polling of analog sensors.
Arduino IDE 2.3.x: Used for coding, compiling, and flashing the firmware onto the ATmega328P microcontroller. Serial Monitor: Utilized during the debugging phase to calibrate joystick thresholds and I2C address discovery.
Adafruit_SSD1306: Essential for handling the display buffer and I2C communication protocol for the SSD1306 OLED. Adafruit_GFX: Provides the graphics core for rendering lines, circles, and text characters. Wire.h: The standard Arduino I2C library used for data transmission between the MCU and the display.
2D Array Representation: The game board is stored in a int board[3][3] matrix, where $0$ is empty, $1$ is 'X', and $2$ is 'O'. Threshold Detection Algorithm: Analog joystick values ($0-1023$) are processed using a hysteresis-like logic ($<300$ and $>700$) to prevent “ghost” movements. Win-Check Algorithm: A deterministic function that scans 8 possible vectors (3 rows, 3 columns, 2 diagonals) for identical non-zero values. Randomized AI Logic: A pseudo-random selection algorithm that identifies available indices in the board matrix to perform automated moves.
setup(): Initializes I2C communication, sets pin modes for joysticks, and seeds the random generator using noise from an open analog pin (A5).
drawMenu(): Handles the UI for mode selection (Single Player vs Multiplayer) and processes Joystick 1 input for navigation.
tttGameLoop(): The core engine that manages turns, calls the input mapping functions, and updates the game state.
botMove(): Implements the automated opponent logic with an artificial delay to simulate human-like interaction. checkWin() & checkDraw(): Logic functions that return boolean values to trigger the end-of-game state. drawTTTGrid(): A dedicated rendering function that draws the board lines and iterates through the matrix to display X and O symbols. playVictorySound() / playDrawSound(): PWM-based functions that use the tone() command to provide audio feedback through the buzzer.