Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pm:prj2025:iivasciuc:marina.oprea2302 [2025/05/19 18:17]
marina.oprea2302 [Game flow]
pm:prj2025:iivasciuc:marina.oprea2302 [2025/05/21 09:09] (current)
marina.oprea2302 [Results]
Line 104: Line 104:
     * updating inner structure of past moves and best score altogether     * updating inner structure of past moves and best score altogether
  
-==== Game flow ====+==== Game flow====
  
 -> At first, a starting menu is displayed and on button press, the game starts. -> At first, a starting menu is displayed and on button press, the game starts.
Line 120: Line 120:
 -> On every move, if grid has changed, a new tile appears in a random position. \\ -> On every move, if grid has changed, a new tile appears in a random position. \\
 -> Bear in mind that if grid **does not change**, **no tile** is added in order to avoid fake moves. -> Bear in mind that if grid **does not change**, **no tile** is added in order to avoid fake moves.
---------------------+ 
 +==== Implementation details ====
 -> Value of new tiles is either ''​2''​ or ''​4'',​ but they are added with different probabilities. \\ -> Value of new tiles is either ''​2''​ or ''​4'',​ but they are added with different probabilities. \\
 -> ''​2''​ appears in 8 out of 10 case, while ''​4''​ otherwise. \\ -> ''​2''​ appears in 8 out of 10 case, while ''​4''​ otherwise. \\
Line 130: Line 131:
 -> Tile position is randomly chosen from list of free positions. \\ -> Tile position is randomly chosen from list of free positions. \\
 -> At game start, randomSeed is initialized with analog value of a floating pin in order to avoid predictibility. -> At game start, randomSeed is initialized with analog value of a floating pin in order to avoid predictibility.
 +----------------------------------
 +-> The ''​XPT2046''​ actually does not return pixel coordinates of touch. \\
 +-> Thus remap using ''​map''​ was needed in order to get from a scale of (0, 4095) to screen pixel dimensions.
 +-----------------------------------------
 +-> For a cleaner code, ''​Grid''​ class was implemented as a wrapper over a simple 4x4 matrix. \\
 +-> This way, overloaded ''​==''​ operator and copy constructor made saving states for undos and performing undo moves easier.
  
 +----------------------------------------------
 +User can choose to use __touchscreen__ or __joystick__.
  
 +In loop function, both variants are polled. Interruptions could not be used because ISR function would have been too complex. Thus I chose polling approach, taking into consideration that playing implies rather continuous moves.
 +------------------------------------------------------------------
 +  * On menu changes, two flags are implied:
 +    * one that is set the first time the menu needs to be displayed
 +    * one that is set the whole time the menu is displayed
 +  * This implements __debouncing__ and also optimizes screen rendering operations.
  
 +
 +
 +-------------------------------------------
 +-> Information is not displayed ,on every frame'​. Thus, throughout the code I used to display different screens once and maintain them unchanged as much as possible.
 +-----------------------------------------
 +-> SPI protocol is fast, but clearing the whole screen and overwriting all pixels is by far visible with human eye. Thus animations that can be implemented cannot be too fast.
 +
 +==== Optimizations ====
 +-> As mentioned above, rerendering is avoided as much as possible. Thus, when screen changes, tile are rendered only if they have different value than before. \\
 +-> When rendering tiles, color is chosen based on their value. In order to perform this efficiently,​ ILI9341 provided colors are stored in an array and bitwise dividing is used in order to find __idx = log2(val)__. \\
 +-> ''​EEPROM.update''​ was used instead of ''​EEPROM.write''​ in order to preserve non-volatile memory lifetime.
 +==== Used labs ====
 +  * Lab0: GPIO
 +    * for joystick button
 +  * Lab4: ADC
 +    * ''​Arduino''​ uses a 10-bit ADC in order to map analog read values from pins used for joystick'​s Vrx, Vry and maps values between 0 and 1023
 +    * ''​XPT2046''​ touchscreen controller uses a 12-bit ADC to convert measured voltage to a value in range 0 - 4095
 +  * Lab5: SPI
 +    * SPI protocol is used to communicate with the display (both for rendering and getting touchscreen input)
 +  * Lab 1: USART
 +    * for debbuging code
 ===== Results ===== ===== Results =====
 +[[https://​github.com/​marinaoprea/​2048_Arduino_minigame|GitHub repository]]
  
-===== Conclusions =====+[[https://​drive.google.com/​file/​d/​1MYe3Vqu2S6hLiaHRXt_nY94sQPNRhBG9/​view?​usp=sharing | Demo video]]
  
-===== Timeline =====+{{https://​drive.google.com/​file/​d/​1Xz-yoFstKYTesYOhvp8GsY_ydz1bZbdR/​view?​usp=sharing|Start screen image}} \\  
 +{{https://​drive.google.com/​file/​d/​1uOEh4WOdCdYd-s7pO7kTfs1R1O7DFJdA/​view?​usp=sharing|Win screen image}} \\  
 +{{https://​drive.google.com/​file/​d/​1Xz-yoFstKYTesYOhvp8GsY_ydz1bZbdR/​view?​usp=sharing|Lose screen image}} \\ 
 +{{https://​drive.google.com/​file/​d/​1_A9DmxYhH7hwRpqK2c7i94b44cIhHxkp/​view?​usp=sharing|Game screen}} \\
  
 +===== Conclusions =====
 +This project was a good opportunity to see how theoretic notions work in real life, applying them the make something entertaining.
  
-===== Bibliography ===== 
  
  
 +===== Bibliography & Other materials =====
 +[[https://​forum.arduino.cc/​t/​interfacing-arduino-with-ili9341-color-tft-display/​1226327|Display interfacing]] \\
 +[[https://​forum.arduino.cc/​t/​interrupts-and-tft/​325116/​35|Interrupts discussions]] \\ 
 +[[https://​www.digikey.com/​en/​resources/​conversion-calculators/​conversion-calculator-resistor-color-code|Resistor color code calculator]] \\
 +[[https://​app.cirkitdesigner.com/​project|Arduino electrical scheme designer]] \\
  
  
pm/prj2025/iivasciuc/marina.oprea2302.1747667831.txt.gz · Last modified: 2025/05/19 18:17 by marina.oprea2302
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0