This repository contains the code for Ball Wall, a simple game built using an Arduino, an OLED display, and button inputs. The game allows the player to move a ball within a bounded area on the OLED screen, controlled by directional buttons. This project is a fun way to learn about graphical rendering, button inputs, and basic game mechanics on microcontrollers.
- Displays a movable ball on a 128x64 OLED screen.
- Uses directional buttons to control the ball's movement (Up, Down, Left, Right).
- Includes boundary checks to restrict the ball's movement within a predefined area.
-
Arduino Board
Compatible with Arduino Uno, Nano, Mega, etc. -
OLED Display
128x64 resolution with SSD1306 driver (I2C communication). -
Buttons (x4)
Used for directional input (Up, Down, Left, Right). -
Miscellaneous:
- Breadboard
- Jumper wires
Connect the components as shown below:
| Component | Arduino Pin |
|---|---|
| OLED SDA | A4 (I2C SDA) |
| OLED SCL | A5 (I2C SCL) |
| Right Button | D2 |
| Left Button | D3 |
| Up Button | D4 |
| Down Button | D5 |
| Power (VCC) | 5V |
| Ground (GND) | GND |
Ensure the buttons are configured with pull-up resistors or use the
INPUT_PULLUPsetting in the code.
-
U8g2 Library
For controlling the OLED display and rendering graphics. -
Wire Library
Built into Arduino for I2C communication.
-
Clone this repository:
git clone https://github.com/yourusername/ball-wall-game.git cd ball-wall-game -
Install the required libraries via Arduino IDE:
- Open Library Manager (
Sketch > Include Library > Manage Libraries...). - Search for "U8g2" and install the library.
- Open Library Manager (
-
Open the
ball_wall.inofile in the Arduino IDE.
- Wire the components as described in the circuit diagram.
- Upload the code to your Arduino board.
- Control the ball using the directional buttons:
- Up, Down, Left, Right to move the ball.
- The ball moves within a predefined boundary displayed on the OLED screen.
- Change boundaries: Modify the
bounds[]array to adjust the allowed movement area. - Speed adjustment: Increase or decrease the movement speed by adjusting the
img[]update values in the code. - Graphics: Replace
image_Pressed_Button_13x13_bitswith custom bitmap graphics for a different ball design.
Contributions to improve this game or expand its functionality are welcome! Feel free to fork the repository, add features, and submit a pull request.
This project is licensed under the MIT License. See LICENSE for more details.