Code Monkey home page Code Monkey logo

manjit-baishya-datascience / pac-man-on-arduino-and-16x2-lcd Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 26 KB

This Arduino project implements a PAC-MAN-style game using an LCD display and push buttons. Players control a snake to eat randomly placed "monsters" for points. Hardware includes an Arduino board, LCD with I2C, and push buttons. Code manages game logic, button inputs, snake movement, and score display on the LCD.

C++ 100.00%
auduino bit-games game i2c-display lcd16x2

pac-man-on-arduino-and-16x2-lcd's Introduction

PAC-MAN in Arduino and I2C LCD Display

header This Arduino project implements a simple PAC-MAN game using an LCD display and push buttons. The game features a snake that moves around the screen, eating randomly placed "monsters" to score points. The player controls the snake's movement using push buttons.

Hardware Requirements

  • Arduino board (e.g., Arduino Uno)
  • LCD display with I2C interface (e.g., 16x2 LiquidCrystal I2C)
  • Push buttons (at least 4)
  • Jumper wires
  • Breadboard (optional)

Software Requirements

  • Arduino IDE
  • LiquidCrystal_I2C library (I2C_lib-1.1.2.zip)

Pin Configuration

  • Connect a 10kΩ resistor across the GND pins of each Push Button(PB).

=======================================================

  • Push Button Signal Out to Arduino PIN connections are as follows:
  • PB 1 --> PIN 2
  • PB 2 --> PIN 4
  • PB 3 --> PIN 7
  • PB 4 --> PIN 8

=======================================================

  • LCD to Arduino PIN connections are as follows:
  • SCL --> A5
  • SDA --> A4
  • VCC --> 5V
  • GND --> GND

=======================================================

Installation and Setup

  1. Connect the LCD display to the Arduino board using the I2C interface.
  2. Connect the push buttons to the Arduino board.
  3. Open the Arduino IDE and install the LiquidCrystal_I2C library if not already installed.
  4. Copy the provided code into a new sketch in the Arduino IDE.
  5. Upload the sketch to the Arduino board.

How to Play

  • Use Button 1 to move the snake left.
  • Use Button 2 to move the snake right.
  • Use Button 3 to move the snake up or down.
  • Use Button 4 to reset the snake to the starting position (0,0).
  • The snake will automatically blink at its current position.
  • Each time the snake eats a monster, the score increases by one and the monster appears at a new location.

Code Explanation

Libraries Used

  • Wire.h: Library for I2C communication.
  • LiquidCrystal_I2C.h: Library for interfacing with LCD using I2C.

Global Variables

  • counter: Counter for dealying the changing of positions of the monster.
  • match: Flag indicating if the snake and monster are at the same position.
  • score: Game score, initialized to -1.
  • X, Y: Current position of the snake.
  • prev_X, prev_Y: Previous position of the snake.
  • monster_X, monster_Y: Current position of the monster.
  • monster_prev_X, monster_prev_Y: Previous position of the monster.
  • snake: Custom character bitmap for the snake.
  • monster: Custom character bitmap for the monster.

Functions

  • setup(): Initializes the LCD, sets pin modes for input buttons, prints initial message and score, and randomizes the seed value.
  • loop(): Main loop of the game. Reads input from buttons, updates snake position, checks for collisions, updates score, and displays everything on the LCD.
  • blinkCursor(int X_cor, int Y_cor): Function to blink the snake at a given position on the LCD.

pac-man-on-arduino-and-16x2-lcd's People

Contributors

manjit-baishya-datascience avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.