Arturo Ambriz / Mbed 2 deprecated Led_Audio_Spectrum

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
chivaa_chino
Date:
Tue May 05 15:33:07 2015 +0000
Parent:
0:6abd8504ab12
Commit message:
hi;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 6abd8504ab12 -r 914cde55e76d main.cpp
--- a/main.cpp	Tue Apr 28 04:43:13 2015 +0000
+++ b/main.cpp	Tue May 05 15:33:07 2015 +0000
@@ -1,4 +1,4 @@
-#include "mbed.h"
+ #include "mbed.h"
 
 DigitalOut colpin1(PTC9);
 DigitalOut colpin2(PTA13);
@@ -20,123 +20,374 @@
 AnalogIn a0(PTB0);
 AnalogIn a1(PTB1);
 
-int left[7];
-int right[7];
+float reads[5];
 int band;
+void rs();
+void lecturas();
 
+void band0(int height);
+void band1(int height);
+void band2(int height);
+void band3(int height);
+void band4(int height);
 Serial pc(USBTX, USBRX);
 
-void readspect();
-void spec(int col, int height);
-
 int main() {
-    
     res = 0;
     strobe = 1;
-    
+    pc.baud(115200);
     while(1) {
-        
-        readspect();
-        
-        // muestra los valores del canal izquierdo en el monitor serial
-        for(band = 0; band < 7; band++ ){
-            pc.printf("%i" ,left[band]);
-            pc.printf(" ");
-            }  
-         pc.printf("\n");   
-        
-        // muestra los valores del canal derecho en el monitor serial
-        for(band = 0; band < 7; band++ ){
-            pc.printf("%i" ,right[band]);
-            pc.printf(" ");
-            }  
-         pc.printf("\n");   
-         
-         spec(colpin1, left[0]);
-         spec(colpin2, left[1]);
-         spec(colpin3, left[2]);
-         spec(colpin4, left[3]);
-         spec(colpin5, left[4]);
-         spec(colpin6, left[5]);
-        spec(colpin7, left[6]);
-
-         /*
-         spec(colpin1, right[0]);
-         spec(colpin2, right[1]);
-         spec(colpin3, right[2]);
-         spec(colpin4, right[3]);
-         spec(colpin5, right[4]);
-         spec(colpin6, right[5]);
-         spec(colpin7, right[6]);
-         */
-         
+    // rs();
+    //lecturas();
+    
+    
+    res = 1;
+    res = 0;
+    for(band = 0; band < 5; band++){
+        strobe = 0;
+float tmplec = a0.read();
+        reads[band] = tmplec*255;
+        strobe = 1;
+        }
+    
+     band0(reads[1]);
+     band1(reads[2]);
+     band2(reads[3]);
+     band3(reads[4]);
+     band4(reads[5]);  
     }
 }
 
 
-void readspect(){ //funciona para leer 7 bandas del ecualizador
+void rs(){ //funciona para leer 7 bandas del ecualizador
     
-    res = 1;
-    res = 0;
-    for(band = 0; band < 7; band++){
-        strobe = 0;
-        wait_us(30);
-        left[band] = a0;
-        right[band] = a1;
-        strobe = 1;
-        }
-    }
     
+}
 
-void spec(int col, int height){ //encender luces de la columna en base a "height"
+void lecturas(){
+    
+     pc.printf("%f",reads[0]);
+      pc.printf("  ");
+      pc.printf("%f",reads[1]);
+      pc.printf("  ");
+      pc.printf("%f",reads[2]);
+      pc.printf("  ");
+      pc.printf("%f",reads[3]);
+      pc.printf("  ");
+      pc.printf("%f",reads[4]);
+      pc.printf("  ");
+      pc.printf("%f",reads[5]);
+      pc.printf("  ");
+      pc.printf("%f",reads[6]);
+      pc.printf("  ");
+      pc.printf("\n");
+    
+    }
+   
     
-    colpin1 = 1;
-    colpin2 = 1;
-    colpin3 = 1;
-    colpin4 = 1;
-    colpin5 = 1;
-    colpin6 = 1;
-    colpin7 = 1;
+ void band0(int height){
+    rowpin1 = 1;
+     
+     if(height>55){
+     colpin1 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 1;
+     rowpin3 = 1;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     if(height>90){
+     colpin1 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 1;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     
+    if(height>125){
+     colpin1 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     
+     if(height>175){
+     colpin1 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 0;
+     rowpin5 = 1;
+     }  
+     
+     
+     
+    if(height>200){
+     colpin1 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 0;
+     rowpin5 = 0;
+     }  
     
-    col = 0;
-    
-    rowpin3 = 0;
-    rowpin4 = 0;
-    rowpin5 = 0;
+     
+}//end function 0
+
+/////////////////////////////////
+void band1(int height){
+   rowpin1 = 1;
+     
+     if(height>55){
+     colpin2 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 1;
+     rowpin3 = 1;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     if(height>90){
+     colpin2 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 1;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     
+    if(height>125){
+     colpin2 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     
+     if(height>175){
+     colpin2 = 1;
+     
+     rowpin1 = 0;   
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 0;
+     rowpin5 = 1;
+     }  
+     
+     
+     
+    if(height>200){
+     colpin2 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 0;
+     rowpin5 = 0;
+     }  
     
-    //para height
-    if(height < 73){
-        rowpin1 = 1;
-        }
-    else{
-        rowpin1 = 0;
-        }
-        
-        
-    if(height < 80){
-        rowpin2 = 1;
-        }
-    else{
-        rowpin2 = 0;
-        }
+     
+}//end function 1
+
+/////////////////////////////////
+void band2(int height){
+   rowpin1 = 1;
+     
+     if(height>55){
+     colpin3 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 1;
+     rowpin3 = 1;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     if(height>90){
+     colpin3 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 1;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     
+    if(height>125){
+     colpin3 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 1;   
+     rowpin5 = 1;
+     }  
+     
+     
+     if(height>175){
+     colpin3 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 0;
+     rowpin5 = 1;
+     }  
+     
+     
+     
+    if(height>200){
+     colpin3 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 0;
+     rowpin5 = 0;
+     }  
+     
+     
+}//end function 2
+
+/////////////////////////////////
+void band3(int height){
+     rowpin1 = 1;
+     
+     if(height>55){
+     colpin4 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 1;
+     rowpin3 = 1;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     if(height>90){
+     colpin4 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 1;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     
+    if(height>125){
+     colpin4 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     
+     if(height>175){
+     colpin4 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 0;
+     rowpin5 = 1;
+     }  
+     
+     
+     
+    if(height>200){
+     colpin4 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 0;
+     rowpin5 = 0;
+     }  
     
-        
-    if(height < 100){
-        rowpin3 = 1;
-        }
-    else{
-        rowpin3 = 0;
-        }
-        
-        
-    if(height < 120){
-        rowpin4 = 1;
-        } 
-        
+     
+}//end function 3
 
-    if(height < 140){
-        rowpin5 = 1;
-        }
-        
-      wait_ms(2);  
-   }
\ No newline at end of file
+/////////////////////////////////
+void band4(int height){
+     rowpin1 = 1;
+     if(height>55){
+     colpin5 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 1;
+     rowpin3 = 1;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     if(height>90){
+     colpin5 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 1;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     
+    if(height>125){
+     colpin5 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 1;
+     rowpin5 = 1;
+     }  
+     
+     
+     if(height>175){
+     colpin5 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 0;
+     rowpin5 = 1;
+     }  
+     
+     
+     
+    if(height>200){
+     colpin5 = 1;
+     
+     rowpin1 = 0;
+     rowpin2 = 0;
+     rowpin3 = 0;
+     rowpin4 = 0;
+     rowpin5 = 0;
+     }  
+    
+     
+}//end function 4
+
+/////////////////////////////////
+     
+