This shows you the differences between two versions of the page.
pm:prj2023:apredescu:gameofsnake [2023/05/28 20:38] mihai.andrei3105 [List of Parts:] |
pm:prj2023:apredescu:gameofsnake [2023/05/28 23:59] (current) mihai.andrei3105 [General Description] |
||
---|---|---|---|
Line 7: | Line 7: | ||
My aim is to try and recreate the game so that anyone can share in the fun of this old-school classic. | My aim is to try and recreate the game so that anyone can share in the fun of this old-school classic. | ||
===== General Description ===== | ===== General Description ===== | ||
- | {{:pm:prj2023:apredescu:andrei_mihai_alexandru_1221a-_diagram.png?700|}} | + | {{:pm:prj2023:apredescu:screenshot_2023-05-28_235828.png?700|}} |
My project uses an Arduino UNO R3 board as its base, as well as an 8x8 Module LED Matrix to display the game itself as well as the score, a Module Joystick to control the Snake's movements during the game and a buzzer that makes noises whenever you pick up a fruit or lose. | My project uses an Arduino UNO R3 board as its base, as well as an 8x8 Module LED Matrix to display the game itself as well as the score, a Module Joystick to control the Snake's movements during the game and a buzzer that makes noises whenever you pick up a fruit or lose. | ||
+ | |||
+ | {{:pm:prj2023:apredescu:andrei_mihai-alexandru_1221a-schematic.png?600|}} | ||
===== Hardware Design ===== | ===== Hardware Design ===== | ||
==== List of Parts: ==== | ==== List of Parts: ==== | ||
Line 21: | Line 23: | ||
{{:pm:prj2023:apredescu:andrei_mihai_alexandru_1221a-_joystick.png?200|}} | {{:pm:prj2023:apredescu:andrei_mihai_alexandru_1221a-_joystick.png?200|}} | ||
* Wires | * Wires | ||
- | * | + | |
Final Design: | Final Design: | ||
+ | |||
{{:pm:prj2023:apredescu:andrei_mihai-alexandru_1221a-progres.jpg?200|}} | {{:pm:prj2023:apredescu:andrei_mihai-alexandru_1221a-progres.jpg?200|}} | ||
===== Software Design ===== | ===== Software Design ===== | ||
- | The code was developed using the Arduino IDE, and the LedControl.h library was used for the LED matrix. | ||
- | The main functions that were used were: | + | 1. The necessary libraries are included, specifically the "LedControl" library for controlling the LED matrix. |
+ | |||
+ | 2. Pin definitions are specified using a struct. Pins for the joystick, LED matrix, and buzzer are defined. | ||
+ | |||
+ | 3. Constants for LED matrix brightness, message scrolling speed, and initial snake length are set. | ||
+ | |||
+ | 4. The `setup()` function is called when the Arduino board starts. It initializes the serial communication, initializes pins and LED matrix, calibrates the joystick, and shows the "snake" message scrolling on the LED matrix. | ||
- | generateFood() | + | 5. The `loop()` function is continuously executed after the `setup()` function. It consists of several steps: |
+ | a. `generateFood()` checks if there is food on the matrix and generates it if necessary. | ||
+ | b. `scanJoystick()` watches the joystick movements and blinks the food on the matrix. | ||
+ | c. `calculateSnake()` calculates the snake movement and updates the LED matrix accordingly. | ||
+ | d. `handleGameStates()` checks for game over conditions, shows the score and game over messages, and resets the game if needed. | ||
- | calculateSnake() | + | 6. Supporting variables and structures are declared, including variables for snake and food positions, joystick calibration values, snake parameters, direction constants, joystick threshold, and gameboard storage. |
- | fixEdge() | + | 7. The code includes various utility functions, such as `playDingSound()` and `playGameOverSong()`, which generate sounds using the buzzer, and `fixEdge()`, which handles snake movement at the edge of the LED matrix. |
- | void handleGameStates() | + | 8. The code also includes functions for calibrating the joystick, initializing the board and LED matrix, and dumping the gameboard for debugging purposes. |
+ | 9. The `snakeMessage` array defines the pattern for the "snake" message displayed on the LED matrix. | ||
+ | Overall, this code implements a basic snake game that runs on an Arduino UNO R3 board and displays the game on a LED matrix. The joystick is used to control the snake's movement, and the game ends when the snake collides with its own body. | ||
===== Results ===== | ===== Results ===== | ||