SEU10f / Mbed 2 deprecated p2_analogin

Dependencies:   mbed

Fork of p2_analogin by Sergio Moyano

Revision:
0:00529fca1abf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hello.cpp	Tue Sep 29 16:53:55 2015 +0000
@@ -0,0 +1,48 @@
+// Flash an LED while a DigitalIn is true
+ 
+#include "mbed.h"
+ 
+AnalogIn   ain(p15);
+Serial pc(USBTX, USBRX); // tx, rx
+
+float media=0;
+float alpha=0.99;
+float actual=0;
+float offset=0.001;
+
+int contador=0;
+
+char state =0;
+char prev_state=0;
+int timeini;
+int timefi;
+Timer timer;
+int main() {
+  
+    media= ain.read();
+    timer.start();
+    while(1) {
+        actual=ain;
+      //  pc.printf("actual %f \n\r",actual);
+       // pc.printf("media %f \n\r",media);
+        media=media*alpha+(1-alpha)*actual;
+        if((actual-media) > offset){
+            state=1;
+            if(prev_state==0){
+                if(contador==0){
+                      timeini = timer.read_us();  
+                      contador++; 
+                }else if(contador==1){   
+                      timefi = timer.read_us();  
+                      pc.printf("Periode %d \n\r",timefi-timeini);
+                      contador=0;
+                }
+            }
+        }else if((actual-media) < offset){
+            state=0;
+            
+        }
+        prev_state = state;
+        wait(0.0002);
+    }
+}