Differences

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

Link to this comparison view

pm:prj2022:arosca:snakegamewithgyroscope [2022/05/23 20:45]
gabriel.saru [Download]
pm:prj2022:arosca:snakegamewithgyroscope [2022/05/27 19:29] (current)
gabriel.saru [Download]
Line 64: Line 64:
 În codul meu am setat lungimea maximă a șarpelui la 64, care este întreaga matrice LED. Am făcut asta pentru că am vrut ca jocul să se termine doar dacă șarpele a murit și nu dacă a ajuns la o anumită lungime. În codul meu am setat lungimea maximă a șarpelui la 64, care este întreaga matrice LED. Am făcut asta pentru că am vrut ca jocul să se termine doar dacă șarpele a murit și nu dacă a ajuns la o anumită lungime.
  
-<​code>​ //First we need to set up some libraries so that we can use all the parts we want+Un mic rezumat in ceea ce fac functiile:​ 
 + 
 +  *    void playGame() ​ --> această funcție va porni jocul 
 +  *    void draw() ​ --> aceasta functie va apela funcțiile pentru a desena șarpele și ținta 
 +  *    void drawSnake() --> aceasta functie va desena sarpele 
 +  *    void drawTarget() --> aceasta functie va atrage ținta 
 +  *    boolean inPlayField(int x, int y) --> va stabili terenul de joc pentru țintă și șarpe pentru a se spawna pe harta 
 +  *    void makeTarget() --> aceasta functie va alege o valoare aleatorie și va stabili ținta 
 +  *    boolean isPartOfSnake(int x, int y) --> ​ aceasta functie se va citi dacă valoarea face parte sau nu din șarpe. 
 +  *    void makeSnake() --> aceasta functie va stabili valorile șarpelui 
 +  *    void moveSnake() --> această funcție va muta șarpele în funcție de accelerometru 
 +  *    void gameOver() --> aceasta functie va afișa spectacolul de lumini și va nota după terminarea jocului 
 + 
 +==== Cod Sursa ==== 
 + 
 +<​code> ​ 
 + 
 +#include <​SparkFun_MMA8452Q.h>​ 
 + 
 + 
 +//First we need to set up some libraries so that we can use all the parts we want
 #include <​Wire.h>​ // we need this to use I2C which is a requirement of the  #include <​Wire.h>​ // we need this to use I2C which is a requirement of the 
 // acceleromter and LED matrix // acceleromter and LED matrix
-#include <​SFE_MMA8452Q.h>​ // this will include the library so we can use the accelerometer+//#include <​SFE_MMA8452Q.h>​ // this will include the library so we can use the accelerometer
  
 //these two libraries are so we can use the LED matrix //these two libraries are so we can use the LED matrix
Line 76: Line 96:
 #include <​SPI.h>​ // needed in Arduino 0019 or later #include <​SPI.h>​ // needed in Arduino 0019 or later
 #include <​Ethernet.h>​ #include <​Ethernet.h>​
-#include <​Twitter.h>​ 
- 
 #include <​EEPROM.h>​ // this will allow us to store memory on the Arduino. #include <​EEPROM.h>​ // this will allow us to store memory on the Arduino.
- 
  
 //Now we need to set up some features for our accelerometer //Now we need to set up some features for our accelerometer
Line 100: Line 117:
 //You can get your token from (http://​arduino-tweet.appspot.com/​) //You can get your token from (http://​arduino-tweet.appspot.com/​)
 //this is my token, make sure to use your own for it to show up on your Twitter news feed //this is my token, make sure to use your own for it to show up on your Twitter news feed
-Twitter twitter("​3196797122-2jESNtWDAvddc1zYJkhaQqUjokUpVwraJ1pAbiS"​);​ 
  
 //this will set up a message which we will use later when we want to post to Twitter //this will set up a message which we will use later when we want to post to Twitter
Line 161: Line 177:
   }   }
   prevPowerState = powerButtonState;​   prevPowerState = powerButtonState;​
- 
-  //​Serial.println(mode);​ //debug to make sure the modes were working porperly 
  
   switch (mode) {   switch (mode) {
Line 179: Line 193:
   int sendButtonState = digitalRead(sendButton);​ //this will send a Tweet of the score by pushing the red button   int sendButtonState = digitalRead(sendButton);​ //this will send a Tweet of the score by pushing the red button
   if (sendButtonState == HIGH) {   if (sendButtonState == HIGH) {
-    sendTweet();​ 
   }   }
 } }
Line 285: Line 298:
  
 void makeSnake() { //this will set up the values of the snake void makeSnake() { //this will set up the values of the snake
 +  ​
   snakeX[0] = 3;   snakeX[0] = 3;
   snakeY[0] = 4;   snakeY[0] = 4;
 +  ​
   for (int i = 1; i < maxSnake; i++) {   for (int i = 1; i < maxSnake; i++) {
     snakeX[i] = snakeY[i] = -1;     snakeX[i] = snakeY[i] = -1;
Line 432: Line 447:
   matrix.setTextColor(LED_YELLOW);​   matrix.setTextColor(LED_YELLOW);​
   matrix.setRotation(3);​   matrix.setRotation(3);​
 +  ​
   for (int8_t x = 7; x >= -36; x--) {   for (int8_t x = 7; x >= -36; x--) {
     matrix.clear();​     matrix.clear();​
Line 439: Line 455:
     delay (100);     delay (100);
   }   }
-}</​code>​+} 
 + 
 + 
 +</​code>​
  
 ====  Rezultate Obţinute ====  ====  Rezultate Obţinute ==== 
  
-TBA+Implementarea proiectului este urmatoarea:
  
 +{{:​pm/​prj2022/​arosca/​rezultat_sgabriel_1_resized.jpg}}
 +{{:​pm/​prj2022/​arosca/​rezultat_sgabriel_2_resized.jpg}}
  
 ===== Concluzii ===== ===== Concluzii =====
-TBA 
  
 +Consider ca proiectul de fata implementat,​ este destul de util pentru o intelegere mai buna a modului de utilizare al unui Arduino, in special functiile sale principale. De asemenea, in implementarea proiectului este folositor pentru ​ a observa si studia modul in care s-a efectuat lucrul cu datele provenite de la mai multe butoane.
 ===== Download ===== ===== Download =====
  
-<note warning>​ +* {{ :pm:​prj2022:​arosca:​arhivaplusreadme_sarugabriel333cb.zip | Arhiva cod sursa + comentarii + README ​}}
-O arhivă (sau mai multe dacă este cazul) cu fişierele obţinute în urma realizării proiectuluisurse, scheme, etcUn fişier ​README, un ChangeLog, un script de compilare şi copiere automată pe uC crează întotdeauna o impresie bună ;-).+
  
-Fişierele se încarcă pe wiki folosind facilitatea **Add Images or other files**. Namespace-ul în care se încarcă fişierele este de tipul **:​pm:​prj20??:​c?​** sau **:​pm:​prj20??:​c?:​nume_student** (dacă este cazul). **Exemplu:​** Dumitru Alin, 331CC -> **:​pm:​prj2009:​cc:dumitru_alin**.+In aceasta sectiune de DOWNLOAD putem gasi arhiva ​care contine urmatoarele:
  
 +  * Codul sursa al proiectului;​
 +  * README, pentru o explicare mai succinta a functiilor din proiect;
 +  * Libraria accelerometrului;​
  
-:​pm:​prj2022:​arosca:​codsursasnakeaccelerometru.zip 
-</​note>​ 
  
 ==== Jurnal ====  ==== Jurnal ==== 
  
  
-Puteți avea și o secțiune de jurnal ​în care să poată urmări ​asistentul de proiect ​progresul proiectului.+Ca o secțiune de jurnal, in care laborantul ​să poată urmări progresul proiectului.
  
   - **Alegere Tema Proiect** ​              - **12.04.2022**   - **Alegere Tema Proiect** ​              - **12.04.2022**
pm/prj2022/arosca/snakegamewithgyroscope.1653327917.txt.gz · Last modified: 2022/05/23 20:45 by gabriel.saru
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