Dependencies:   PCA9955A_library_prototype mbed

Revision:
6:4da1c7f560b8
Parent:
5:78bfbf11bb2f
Child:
7:40f2b0db16a6
--- a/main.cpp	Thu Jul 17 02:08:37 2014 +0000
+++ b/main.cpp	Thu Jul 17 07:48:12 2014 +0000
@@ -25,12 +25,13 @@
 int main()
 {
     float   in;
-    float   coef    = 26.4;
-    float   peak    = 0;
+    float   coef        = 26.4;
+    float   peak        = 0;
+    float   thresold    = 0.05;
     int     shift;
 
     led_driver.set_all_intensity( 0xFF );
-    led_driver.set_all_intensity( 0x20, true );
+    led_driver.set_all_intensity( 0x40, true );
 
     set_color( 1 );
 
@@ -44,21 +45,37 @@
 
             pin =0;
             in      = (float)ain;
-            peak    = in < peak ? peak : in;
+
+            if ( 0.06 < in ) {
+                if ( peak < in ) {
+                    if ( thresold < (in - peak) ) {
+                        thresold    = in - peak;
+                        led_change  = 1;
+                    }
+                    peak    = in;
+                }
+            }
+
             shift  = (int)(coef * peak);
             leds    = 0x1 << shift;
             peak    *= 0.99;
+            thresold*= (thresold < 0.07) ? 0.07 : thresold * 0.9;
             pin =1;
             aout    = peak;
 
             if ( shift > 2 ) {
-                led_change  = 1;
+                //led_change  = 1;
             }
         }
     }
 
 }
 
+
+int peak_detect()
+{
+    }
+
 void ad_cntl()
 {
     sampling    = 1;