This shows you the differences between two versions of the page.
pm:prj2025:iivasciuc:marina.oprea2302 [2025/05/20 22:46] marina.oprea2302 [Conclusions] |
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 interaction ==== | + | ---------------------------------------------- |
- | User can choose to use touchscreen or joystick. | + | 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. | 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. | ||
- | 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. |
- | ----------- | + | ----------------------------------------- |
- | 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. |
- | ------------ | + | |
- | 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 ==== | ==== 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. \\ | -> 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)__. | + | -> 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 ==== | ==== Used labs ==== | ||
* Lab0: GPIO | * Lab0: GPIO | ||
Line 161: | Line 171: | ||
===== Results ===== | ===== Results ===== | ||
[[https://github.com/marinaoprea/2048_Arduino_minigame|GitHub repository]] | [[https://github.com/marinaoprea/2048_Arduino_minigame|GitHub repository]] | ||
+ | |||
+ | [[https://drive.google.com/file/d/1MYe3Vqu2S6hLiaHRXt_nY94sQPNRhBG9/view?usp=sharing | Demo video]] | ||
{{https://drive.google.com/file/d/1Xz-yoFstKYTesYOhvp8GsY_ydz1bZbdR/view?usp=sharing|Start screen image}} \\ | {{https://drive.google.com/file/d/1Xz-yoFstKYTesYOhvp8GsY_ydz1bZbdR/view?usp=sharing|Start screen image}} \\ | ||
Line 169: | Line 181: | ||
===== Conclusions ===== | ===== Conclusions ===== | ||
This project was a good opportunity to see how theoretic notions work in real life, applying them the make something entertaining. | This project was a good opportunity to see how theoretic notions work in real life, applying them the make something entertaining. | ||
- | ===== Timeline ===== | ||
- | |||
- | ===== 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]] \\ | ||