juego 2

Dependencies:   mbed MPU6050

Revision:
1:17e8d7967b5a
Parent:
0:adbdc52e1846
Child:
2:205af2fe4225
diff -r adbdc52e1846 -r 17e8d7967b5a main.cpp
--- a/main.cpp	Fri Nov 16 04:25:15 2018 +0000
+++ b/main.cpp	Fri Nov 16 12:15:24 2018 +0000
@@ -3,13 +3,16 @@
 SPI deviceM(PB_15, PB_14, PB_13);
 DigitalOut ssel (PB_12);
 Serial a(USBTX,USBRX);
+Ticker cambio;
 MPU6050 Wire(PB_9,PB_8);
 InterruptIn iz(PA_14);
 InterruptIn de(PA_13);
 #define  uint8_t unsigned char
+float q[3];
 int pos;
 float vel=200;
 int b;
+uint8_t cam[3]={0b01100000,0b00011000,0b00000110};
 uint8_t Matr[9]={0,0,0,0,0,0,0,0,0};
 uint8_t entorno={0b10000001};
 uint8_t carro={0b00011000};
@@ -19,7 +22,9 @@
 void colision();
 void juego();
 void accelerometro();
+void cambiof();
 int con;
+int az;
 
 void sendSPI(uint8_t d1, uint8_t d2)
 {
@@ -99,12 +104,14 @@
 }
 
 int main() {
+     cambio.attach(&cambiof,0.2);
      while(1){
-     //accelerometro();
+     accelerometro();
      juego();        
         }
 }
 
+
 void juego(){
                     inicializar();   
                     de.fall(&derecha);  
@@ -146,17 +153,33 @@
 }
 
 void accelerometro(){
-    int holi;
-         Wire.setAcceleroRange('MPU6050_ACCELERO_RANGE_16G');
-         int accelero[3]; Wire.getAcceleroRaw(accelero);
+         
+         Wire.getAccelero(q);
+         a.printf("accelero: \t x=  %f,\t y=  %f, \t z= %f \n",q[0],q[1],q[2]);
+         int accelero[3]; 
+         //Wire.getAcceleroRaw(accelero);
          int valor=accelero[1];
          if(valor<=(2000) && valor>=(1000)){
-           holi=1;}
+           az=1;}
          if(valor<(1000) && valor>=(-1000)){
-           holi=2;}
+           az=2;}
          if(valor<(-1000) && valor>=(-2000)){
-           holi=3;}
-         a.printf("holi : \t  %d \n",holi);        
+           az=3;}
+         a.printf("holi : \t  %d \n",az);        
          wait(0.8);
          
     }
+
+void cambiof(){
+    
+    switch (az){
+        case 1: carro=cam[1];
+        break;
+        case 2: carro=cam[2];
+        break;
+        case 3: carro=cam[3];
+        break;
+        }
+    
+    
+    }
\ No newline at end of file