Programa de MIP

Dependencies:   bloques ball mbed WS2812 PixelArray tsi_sensor TSI bloque MMA8451Q

Revision:
20:6f5f486bd5c3
Parent:
19:e57116ff4c59
Child:
21:88d30cb63bc1
--- a/main.cpp	Wed May 26 18:28:49 2021 +0000
+++ b/main.cpp	Thu May 27 18:39:12 2021 +0000
@@ -36,10 +36,13 @@
 Ticker refresh_ball;
 bloques Bloques;
 Ticker refresh_bloques;
+Ticker refresh_InfoMode;
 int cont_ball_rebote=0;
-
+bool settedMode=false;
 int angle=1;
 bool lose=false;
+int sel_opcio=0;
+int contModePrintInfo=0;
 
 void update_barra(int led_apagar, int led_encender, int act_barra );
 void tsi_ctr_modeBtn(float tsi_newRead);
@@ -51,14 +54,43 @@
 void clear_matrix(int offset);
 void angle_rebote();
 bool addLineOfBloques();
+void printBtnMode();
+void printSliderMode();
+void printAccelMode();
+void cyclePrintModeInfo();
+
 
 int main()
 {   
-    int sel_opcio=0;
+    
     pc.baud(115200);
     pc.printf("\r\n\r\nHola!\r\ncompilado el " __DATE__ ", " __TIME__ "\r\n");
     
     wsLEDS.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling
+    
+    refresh_InfoMode.attach(&cyclePrintModeInfo,4.0);
+    
+    while(settedMode==false){
+        float tsi_readTemp=tsi.readPercentage();
+        pc.printf("\r\n Touch %d", tsi_readTemp);
+        if(tsi_readTemp!=0.0){
+            if(tsi_readTemp>0.01 and tsi_readTemp<0.33){
+                sel_opcio=0;
+                settedMode=true;
+            }else if(tsi_readTemp>=0.33 and tsi_readTemp<=0.66){
+                sel_opcio=1;
+                settedMode=true;
+            }else if(tsi_readTemp>0.66 and tsi_readTemp<=1.00){
+                sel_opcio=2;
+                settedMode=true;
+            }
+        }
+    }
+    
+    refresh_InfoMode.detach();
+    clear_matrix(0);
+    
+    
     for(int i=0; i<Bloques.getNumBloques(); i++){
         bloque temp_blq=Bloques.getBloque(i);
         print_pixel(temp_blq.getColR(),temp_blq.getColG(),temp_blq.getColB(), temp_blq.getCoordX(),temp_blq.getCoordY(), -1, -1, temp_blq.getSize());
@@ -77,7 +109,11 @@
     
     refresh_ball.attach(&ctr_ball, 0.1);
     //refresh_bloques.attach(&addLineOfBloques, 7);
-    while (1) {
+    
+    
+
+    
+    while (settedMode==true) {
         if(sel_opcio==0){
             tsi_ctr_modeBtn(tsi.readPercentage());
         }
@@ -393,8 +429,8 @@
                     if(!direct_ball){
                         angle_rebote();
                     }else{
-                        m_ball.setCoordX(next_CoordX);
-                        m_ball.setCoordY(predict_Y);
+                        //m_ball.setCoordX(next_CoordX);
+                        //m_ball.setCoordY(predict_Y);
                     }
                 }
                 j++;
@@ -441,3 +477,159 @@
     
 }
 
+void printBtnMode(){
+    
+    //Base gris del mando
+    for(int f=5; f<10; f++){
+        for(int c=3; c<13; c++){
+            print_pixel(199,200,205, f,c, -1, -1);
+        }    
+    }
+    
+    //Barra inferior posicionamiento a tocar
+    for(int f=0; f<3; f++){
+        for(int c=0; c<5; c++){
+            print_pixel(0,255,0, f,c, -1, -1);
+        }
+        for(int c=5; c<16; c++){
+            print_pixel(255,0,0, f,c, -1, -1);
+        }  
+    }
+    
+    //Cruceta del mando (iquierda)
+    print_pixel(20,20,20, 6,5, -1, -1);
+    print_pixel(20,20,20, 7,5, -1, -1);
+    print_pixel(20,20,20, 8,5, -1, -1);
+    print_pixel(20,20,20, 7,4, -1, -1);
+    print_pixel(20,20,20, 7,6, -1, -1);
+    
+    //Botones del mando (derecha)
+    print_pixel(224,180,44, 6,10, -1, -1);
+    print_pixel(32,139,87, 7,9, -1, -1);
+    print_pixel(189,26,26, 7,11, -1, -1);
+    print_pixel(22,70,177, 8,10, -1, -1);
+    
+    //Letra L
+    print_pixel(200,200,0, 11,3, -1, -1);
+    print_pixel(200,200,0, 11,4, -1, -1);
+    print_pixel(200,200,0, 11,5, -1, -1);
+    print_pixel(200,200,0, 12,3, -1, -1);
+    print_pixel(200,200,0, 13,3, -1, -1);
+    print_pixel(200,200,0, 14,3, -1, -1);
+    
+    //Letra R
+    print_pixel(200,200,0, 11,10, -1, -1);
+    print_pixel(200,200,0, 11,12, -1, -1);
+    print_pixel(200,200,0, 12,10, -1, -1);
+    print_pixel(200,200,0, 12,11, -1, -1);
+    print_pixel(200,200,0, 13,10, -1, -1);
+    print_pixel(200,200,0, 13,12, -1, -1);
+    print_pixel(200,200,0, 14,10, -1, -1);
+    print_pixel(200,200,0, 14,11, -1, -1);
+    print_pixel(200,200,0, 14,12, -1, -1);
+    
+    wsLEDS.write(px.getBuf());
+}
+
+void printSliderMode(){
+    
+    //Base gris del slider
+    for(int c=1; c<15; c++){
+        print_pixel(255,255,255, 12,c, -1, -1);   
+    }
+    
+    //Parte azul slider
+    print_pixel(0,0,205, 11,5, -1, -1); 
+    print_pixel(0,0,205, 12,5, -1, -1); 
+    print_pixel(0,0,205, 13,5, -1, -1); 
+    
+    //flecha
+    for(int c=1; c<15; c++){
+        print_pixel(249,215,28, 7, c, -1, -1);   
+    }
+    
+    print_pixel(249,215,28, 8,2, -1, -1); 
+    print_pixel(249,215,28, 9,3, -1, -1); 
+    print_pixel(249,215,28, 6,2, -1, -1); 
+    print_pixel(249,215,28, 5,3, -1, -1); 
+    print_pixel(249,215,28, 8,13, -1, -1); 
+    print_pixel(249,215,28, 9,12, -1, -1); 
+    print_pixel(249,215,28, 6,13, -1, -1); 
+    print_pixel(249,215,28, 5,12, -1, -1); 
+    
+    
+    
+    //Barra inferior posicionamiento a tocar
+    for(int f=0; f<3; f++){
+        for(int c=0; c<5; c++){
+            print_pixel(255,0,0, f,c, -1, -1);
+        } 
+        for(int c=5; c<11; c++){
+            print_pixel(0,255,0, f,c, -1, -1);
+        }
+        for(int c=11; c<16; c++){
+            print_pixel(255,0,0, f,c, -1, -1);
+        }  
+    }
+    
+    
+    wsLEDS.write(px.getBuf());
+}
+
+void printAccelMode(){
+    
+    //Base gris de la placa acelerometro
+    for(int f=6; f<14; f++){
+        for(int c=11; c<16; c++){
+            print_pixel(255,255,255, f,c, -1, -1);
+        }    
+    }
+    
+    //Parte interna placa
+    for(int f=7; f<9; f++){
+        for(int c=12; c<15; c++){
+            print_pixel(118,118,109, f,c, -1, -1);
+        }    
+    }
+    
+    //flecha
+    print_pixel(249,215,28, 6,4, -1, -1, 3); 
+    print_pixel(249,215,28, 7,1, -1, -1); 
+    print_pixel(249,215,28, 7,3, -1, -1); 
+    print_pixel(249,215,28, 7,7, -1, -1); 
+    print_pixel(249,215,28, 7,9, -1, -1); 
+    print_pixel(249,215,28, 8,1, -1, -1, 2); 
+    print_pixel(249,215,28, 8,8, -1, -1, 2); 
+    print_pixel(249,215,28, 9,1, -1, -1, 3); 
+    print_pixel(249,215,28, 9,7, -1, -1, 3);
+    
+    
+    //Barra inferior posicionamiento a tocar
+    for(int f=0; f<3; f++){
+        for(int c=0; c<11; c++){
+            print_pixel(255,0,0, f,c, -1, -1);
+        } 
+        for(int c=11; c<16; c++){
+            print_pixel(0,255,0, f,c, -1, -1);
+        }  
+    }
+    
+    
+    wsLEDS.write(px.getBuf());
+}
+
+void cyclePrintModeInfo(){
+    if(contModePrintInfo==0){
+        clear_matrix(0);
+        printBtnMode();
+        contModePrintInfo++;
+    }else if(contModePrintInfo==1){
+        clear_matrix(0);
+        printSliderMode();
+        contModePrintInfo++;
+    }else{
+        clear_matrix(0);
+        printAccelMode();
+        contModePrintInfo=0;
+    }
+}