Programa de MIP

Dependencies:   bloques ball mbed WS2812 PixelArray tsi_sensor TSI bloque MMA8451Q

Revision:
9:777b0535d3bb
Parent:
8:9e69e576d1be
Child:
10:dccb2be41fbd
--- a/main.cpp	Sat May 22 16:46:49 2021 +0000
+++ b/main.cpp	Sat May 22 18:02:43 2021 +0000
@@ -3,6 +3,7 @@
 #include "PixelArray.h"
 #include "TSISensor.h"
 #include "MMA8451Q.h"
+#include "ball.h"
 
 
 #define WS2812_BUF 256
@@ -30,23 +31,16 @@
 int posAcelerometerTemp, posAcelerometer=0, posAcelerometerOLD=0, posAcelerometerOLD1=0, contadorReboteA=0;
 int posSliderTouchTemp, posSliderTouch=0, posSliderTouchOLD=0, posSliderTouchOLD1=0, contadorRebote=0;
 int matrix_tablero[DIMENSION_TABLERO][DIMENSION_TABLERO]={};
-int pelota[2]={8,8}; //valor x en posicion 0 y valor y en posicion 1
+ball m_ball;
 
-//int pixel=8;
 
-//void control_tsi(float tsi_newRead);
-//void control_accel();
+
 void update_barra(int led_apagar, int led_encender, int act_barra );
 void tsi_ctr_modeBtn(float tsi_newRead);
 void tsi_ctr_modeSlider(float tsi_newRead);
 void accel_ctr();
-
-void setPixelColor(int numPixelMatrix, int r, int g, int b){
-    px.SetI(numPixelMatrix,255);
-    px.SetR(numPixelMatrix,r);
-    px.SetG(numPixelMatrix,g);
-    px.SetB(numPixelMatrix,b);
-}
+void print_pixel(uint8_t valR, uint8_t valG, uint8_t valB, int numPixelMatrix_i, int numPixelMatrix_j, int numPixelMatrixOLD_i, int numPixelMatrixOLD_j);
+void setPixelColor(int numPixelMatrix, int r, int g, int b);
 
 int main()
 {   int sel_opcio=7;
@@ -67,27 +61,19 @@
     for(int i=0; i<NUM_LEDS_BARRA; i++){
         px.Set(barra[i], 0x2f0000);
     }
-    //px.SetR(64, 0);
-    //px.SetG(64, 255);
-    //px.SetB(64, 0);
+
     for(int i=0; i<NUM_LEDS_BARRA; i++){
         px.SetI(barra[i]%WS2812_BUF, 255); //0xff
     }
-    //px.SetI(64, 255);
+
  
-    for(int i=0; i<NUM_LEDS_BARRA; i++){
+    /*for(int i=0; i<NUM_LEDS_BARRA; i++){
         matrix_tablero[0][barra[i]]=1;
-    }
+    }*/
     
-    setPixelColor(64,0,255,0);
-    // now all the colours are computed, add a fade effect using intensity scaling
-    // compute and write the II value for each pixel
-    /*for (int j=0; j<WS2812_BUF; j++) {
-        // px.SetI(pixel position, II value)
-        px.SetI(j%WS2812_BUF, 0xf+(0xf*(j%NUM_LEDS_PER_COLOR)));
-    }
- 
-    */
+    print_pixel(255, 255, 255, m_ball.getCoordX(), m_ball.getCoordY(),-1,-1);
+
+
     // Now the buffer is written, rotate it
     // by writing it out with an increasing offset
     ws.write(px.getBuf());
@@ -108,6 +94,8 @@
             }
         }   
         
+        pc.printf("\r\n Touch %d", (rand()%(9-6 + 1) + 6));
+        
     }
  
 }
@@ -205,44 +193,7 @@
     
 }
 
-/*void control_tsi(float tsi_newRead){
-    float percent= tsi_newRead; //tsi.readPercentage();
-    if( (percent < 0.4) && percent!=0 ){ //if left
-        if(barra[0]>0){
-            px.Set(barra[NUM_LEDS_BARRA-1], 0x0);  //apagamos el último led
-                //px.SetI(barra[NUM_LEDS_BARRA-1]%WS2812_BUF, 0x0);
-            
-            for(int i=0; i<NUM_LEDS_BARRA; i++){ //actualizamos valor del array
-                barra[i]=barra[i]-1;
-            }
-            
-            px.Set(barra[0], 0x2f0000); //encendemos el siguiente led a la izquierda
-            px.SetI(barra[0]%WS2812_BUF, 0xff);
-            
-            //update_barra((NUM_LEDS_BARRA-1),0, -1 );
-        }
-    }
-    else{
-        if(percent > 0.6){ //if right
-            if(barra[NUM_LEDS_BARRA-1]<15){
-                px.Set(barra[0], 0x0);  //apagamos el primer led
-                //px.SetI(barra[0]%WS2812_BUF, 0x0);
-                
-                for(int i=0; i<NUM_LEDS_BARRA; i++){ //actualizamos valor del array
-                    barra[i]=barra[i]+1;
-                }
-                
-                px.Set(barra[NUM_LEDS_BARRA-1], 0x2f0000); //encendemos el siguiente led a la derecha
-                px.SetI(barra[NUM_LEDS_BARRA-1]%WS2812_BUF, 0xff);
-                
-                //update_barra(0,(NUM_LEDS_BARRA-1), 1 );
-            }
-            
-        }
-    }
-    
-    //ws.write(px.getBuf());
-}*/
+
 void update_barra(int led_apagar, int led_encender, int act_barra ){
     px.Set(barra[led_apagar], 0x0);  //apagamos el led
                 
@@ -304,4 +255,41 @@
     }
 }
 
+void print_pixel(uint8_t valR, uint8_t valG, uint8_t valB, int numPixelMatrix_i, int numPixelMatrix_j, int numPixelMatrixOLD_i, int numPixelMatrixOLD_j) {
+    
+    //printf ("\r\nRGB=> %ld, %ld, %ld \r\n", valR, valG, valB);
+    int numPixelMatrix;
+    if(numPixelMatrix_i%2==0){
+        numPixelMatrix=((numPixelMatrix_i*16)+15)-numPixelMatrix_j;
+    }else{
+        numPixelMatrix=(numPixelMatrix_i*16)+numPixelMatrix_j;
+    }
+    
+    if(numPixelMatrixOLD_i!=-1 and numPixelMatrixOLD_j!=-1){
+        
+        int numPixelMatrixOLD;
+        if(numPixelMatrixOLD_i%2==0){
+            numPixelMatrixOLD=((numPixelMatrixOLD_i*16)+15)-numPixelMatrixOLD_j;
+        }else{
+            numPixelMatrixOLD=(numPixelMatrixOLD_i*16)+numPixelMatrixOLD_j;
+        }        
+        
+        setPixelColor(numPixelMatrixOLD, 0, 0, 0);
+            
+    }
+        
+    
+    setPixelColor(numPixelMatrix, valR, valG, valB);    
+    ws.write(px.getBuf());
+    
+}
 
+void setPixelColor(int numPixelMatrix, int r, int g, int b){
+    px.SetI(numPixelMatrix,255);
+    px.SetR(numPixelMatrix,r);
+    px.SetG(numPixelMatrix,g);
+    px.SetB(numPixelMatrix,b);
+}
+
+
+