This shows you the differences between two versions of the page.
pm:prj2025:iotelea:stefan.basaram [2025/05/26 19:57] stefan.basaram [Software Design] first draft |
pm:prj2025:iotelea:stefan.basaram [2025/05/26 20:43] (current) stefan.basaram added results and references |
||
---|---|---|---|
Line 43: | Line 43: | ||
* [[https://www.emag.ro/baterie-philips-longlife-9v-1-blister-6f22l1b-10/pd/DRC1LKBBM/? utm_campaign=share_product&utm_source=mobile_dynamic_share&utm_medium=android|9V Battery]] + [[https://www.optimusdigital.ro/ro/fire-fire-mufate/896-fir-pentru-baterie-de-9v.html|Adapter]] - Allows the console to be used without being tethered to a computer. | * [[https://www.emag.ro/baterie-philips-longlife-9v-1-blister-6f22l1b-10/pd/DRC1LKBBM/? utm_campaign=share_product&utm_source=mobile_dynamic_share&utm_medium=android|9V Battery]] + [[https://www.optimusdigital.ro/ro/fire-fire-mufate/896-fir-pentru-baterie-de-9v.html|Adapter]] - Allows the console to be used without being tethered to a computer. | ||
* Cables [[https://www.optimusdigital.ro/ro/fire-fire-mufate/885-set-fire-tata-tata-10p-10-cm.html|male-male]] and [[https://www.optimusdigital.ro/ro/fire-fire-mufate/92-fire-colorate-mama-tata-40p.html|male-female]] | * Cables [[https://www.optimusdigital.ro/ro/fire-fire-mufate/885-set-fire-tata-tata-10p-10-cm.html|male-male]] and [[https://www.optimusdigital.ro/ro/fire-fire-mufate/92-fire-colorate-mama-tata-40p.html|male-female]] | ||
- | * [[https://www.bitmi.ro/electronica/breadboard-400-puncte-pentru-montaje-electronice-rapide-10633.html|Breadboard]] - Used for wiring together the display and player inputs, as well as powering the passive buzzer. | + | * [[https://www.bitmi.ro/electronica/breadboard-400-puncte-pentru-montaje-electronice-rapide-10633.html|Breadboard]] - Used for wiring together the display, player inputs and the buzzer. |
{{pm:prj2025:iotelea:stefan.basaram:schema_electrica_consola.png?750 }} | {{pm:prj2025:iotelea:stefan.basaram:schema_electrica_consola.png?750 }} | ||
Line 64: | Line 64: | ||
|::: | ::: | A1 <- VRy | ::: | | |::: | ::: | A1 <- VRy | ::: | | ||
|::: | Digital | D4 <- SW | Button press state can be read digitally | | |::: | Digital | D4 <- SW | Button press state can be read digitally | | ||
- | |Passive buzzer | Digital (PWM) | D3 -> Buzzer | The use of PWM enables adjusting the volume of the buzzer, along with its tone | | + | |Passive buzzer | Digital (PWM) | D3 -> Buzzer | The use of PWM enables adjusting the volume of the buzzer, along with its tone | |
Line 77: | Line 77: | ||
Development includes the use of both .ino files and C++ files, as such I used two IDEs | Development includes the use of both .ino files and C++ files, as such I used two IDEs | ||
* Arduino IDE - for the only .ino file **Console.ino** which is concerned with interacting with the Arduino | * Arduino IDE - for the only .ino file **Console.ino** which is concerned with interacting with the Arduino | ||
- | * VSCode - programming the games and integrating them with **Console.ino**. Using VSCode instead of Arduino IDE for source files had many benefits including better syntax highlighting, more functional text-editor and accessible version control via Github. | + | * Visual Studio Code (VSCode) - programming the games and integrating them with **Console.ino**. Using VSCode instead of Arduino IDE for source files had many benefits including better syntax highlighting, more functional text-editor and accessible version control via Github. |
- | For 3rd party libraries I used [[http://www.wayoda.org/arduino/ledcontrol/|LedControl]] which was a necessary addition in order to use the LED Matrces of type MAX7219 which have a unique hardware interface composed of 5 pins. | + | For 3rd party libraries I used [[http://www.wayoda.org/arduino/ledcontrol/|LedControl]] which was a necessary addition in order to use the LED matrices of type **MAX7219** which have a unique hardware interface composed of 5 pins. |
=== Architecture === | === Architecture === | ||
Line 88: | Line 88: | ||
* reads user input | * reads user input | ||
* plays sound | * plays sound | ||
- | * updates screen using two LedControllers, provided by the library mentioned above, one for each LED matrixsubsequently called from Console.ino as mentioned | + | * updates screen using two LedControllers, provided by the library mentioned above, one for each LED matrix |
=== Console.ino === | === Console.ino === | ||
- | It has main role of instantiating the game engine and handling the hardware side of the game. | + | It contains the main loop and has the role of managing and updating the engine and the active game as well as cycling the games. |
The main functions are **setup()** and **loop()**, with the auxiliary functions: **switchGame()**, **handleGames(float deltaTime)** and **startupSequence()** | The main functions are **setup()** and **loop()**, with the auxiliary functions: **switchGame()**, **handleGames(float deltaTime)** and **startupSequence()** | ||
Line 113: | Line 113: | ||
== Drawing system == | == Drawing system == | ||
- | The drawing system stores 2 arrays of 8 bytes, with one bit for each LED. Each array is associated with an LED matrix and also each LED matrix gets its own controller of type **LedControl** provided by the 3rd library mentioned above. When setting a pixel on the screen, it doesn't immediately update the LED matrices. It first determines which LED matrix is affected and updates the corespondent array of bytes using bitwise operations. When the game state is updated, the arrays of bytes are sent row by row to the LED controllers which change the LEDs matrices.\\ | + | The drawing system stores 2 arrays of 8 bytes, with one bit for each LED. Each array is associated with an LED matrix and also each LED matrix gets its own controller of type **LedControl** provided by the 3rd library mentioned above. When setting a pixel on the screen, it doesn't immediately update the LED matrices. It first determines which LED matrix is affected and updates the correspondent array of bytes using bitwise operations. When the game state is updated, the arrays of bytes are sent row by row to the LED controllers which change the LEDs matrices.\\ |
For performance reasons, we cannot update each LED individually. Also, because the actual LED matrices composing the physical screen have different orientations, we must change how each LED matrix is updated. | For performance reasons, we cannot update each LED individually. Also, because the actual LED matrices composing the physical screen have different orientations, we must change how each LED matrix is updated. | ||
Line 138: | Line 138: | ||
=== Games === | === Games === | ||
- | I took an approach inspired by OOP design principles and implemented the games using polymorphism and inheritance. I made a Game interface with an **updateLoop()** function which must be implemented by any game which wishes to be added. Console.ino holds a reference to the current game and calls the updateLoop function which calls the correct derivative function depending on the underlying game class.\\ | + | I took an approach inspired by OOP design principles and implemented the games using polymorphism and inheritance. I made a Game interface with an **updateLoop()** function which must be implemented by any game which wishes to be added. Console.ino holds a reference to the current game and calls the **updateLoop()** function which calls the correct derivative function depending on the underlying game class.\\ |
- | Each game holds a reference to the Engine, fact enforced by the Game interface, which allows it to read the current state of user input, play sounds and update the screen as well as access details about the engine such as the delta time and the time since the last move has occured. | + | Each game holds a reference to the Engine, fact enforced by the Game interface, which allows it to read the current state of user input, play sounds and update the screen as well as access details about the engine such as the delta time and the time since the last move has occurred. |
There are 3 games implemented: | There are 3 games implemented: | ||
Line 152: | Line 152: | ||
If the head of the snake occupies the same position as one of its body, the snake is killed and one of the player's lives is taken. If the player has not run out their 3 lives, they may continue playing from the point just before the collision occured, with the game resuming upon the player's next input. | If the head of the snake occupies the same position as one of its body, the snake is killed and one of the player's lives is taken. If the player has not run out their 3 lives, they may continue playing from the point just before the collision occured, with the game resuming upon the player's next input. | ||
+ | When all lives are exausted, an animation is played which shows how large the snake had grown before it died. | ||
== Asteroids == | == Asteroids == | ||
- | The player encompases a spaceship on the left side of the screen and must shoot incoming asteroids (presumably, since the display resolution allows room for creative interpretation).\\ | + | The player encompasses a spaceship on the left side of the screen and must shoot incoming asteroids (presumably, since the display resolution allows room for creative interpretation).\\ |
In **updateLoop()**, the spaceship is moved up or down with the joystick and fires with a normal button press. Asteroids are spawned randomly on right side of the screen and approach the player's ship. Firing makes a noise.\\ | In **updateLoop()**, the spaceship is moved up or down with the joystick and fires with a normal button press. Asteroids are spawned randomly on right side of the screen and approach the player's ship. Firing makes a noise.\\ | ||
If the player is clipped by an asteroid, their ship is destroyed. This game does not have lives and the player will simply be prompted to try again or move to the next game. | If the player is clipped by an asteroid, their ship is destroyed. This game does not have lives and the player will simply be prompted to try again or move to the next game. | ||
Line 160: | Line 161: | ||
== Pong == | == Pong == | ||
Hang on, isn't pong a 2 player game? Or played with an A.I?\\ | Hang on, isn't pong a 2 player game? Or played with an A.I?\\ | ||
- | In my version of Pong, the player controls BOTH paddles, one at a time. After a paddle reflects the ball, contol is immediately switched to the other paddle and the player must react fast enough to continue to reflect the ball. The game starts with an active paddle and a random ball trajectory.\\ | + | In my version of Pong, the player controls BOTH paddles, one at a time. After a paddle reflects the ball, control is immediately switched to the other paddle and the player must react fast enough to continue to reflect the ball. The game starts with an active paddle and a random ball trajectory.\\ |
- | In **updateLoop()**, the currently active paddle is moved by the joystick. The paddle is not terribily big, however it moves very fast. If the ball collides with the paddle, the ball is reflected and control is passed to the other paddle. The speed of the ball increases over time.\\ | + | In **updateLoop()**, the currently active paddle is moved by the joystick. The paddle is not terribly big, however it moves very fast. If the ball collides with the paddle, the ball is reflected and control is passed to the other paddle. The speed of the ball increases over time.\\ |
If the ball goes past the paddle, the player loses a life. If the player has not run out their 3 lives, they get to keep playing with the last speed of the ball preserved and starting from the losing paddle. | If the ball goes past the paddle, the player loses a life. If the player has not run out their 3 lives, they get to keep playing with the last speed of the ball preserved and starting from the losing paddle. | ||
+ | |||
+ | ===== Results ===== | ||
+ | * [[https://youtube.com/shorts/Nj0hMh7GVlk?feature=share|Prototype video]] | ||
+ | |||
+ | ===== References ===== | ||
+ | * [[https://www.arduino.cc/en/Guide/ArduinoUno/#upload-the-program| Getting started with Arduino]] | ||
+ | * [[http://www.wayoda.org/arduino/ledcontrol/|LED Control Library for LED Display Matrices]] | ||
+ | * [[https://forum.arduino.cc/t/avrdude-ser-open-cant-set-com-state-for-com3-failed-uploading-uploading-error-exit-status-1/1131626/18|Driver fix by ptillisch for the Arduino model used here]] | ||
+ | * [[https://xantorohara.github.io/led-matrix-editor/#42844a0035153377|LED Matrix Editor]] | ||