Mesure sur 1 seconde avec moyenneage

Dependencies:   mbed

Revision:
0:14c42a61cdb2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 22 07:37:57 2018 +0000
@@ -0,0 +1,54 @@
+#include "mbed.h"
+
+Serial pc (USBTX, USBRX);
+AnalogIn ain(p17); 
+DigitalOut led(p7);
+
+float f ;
+float silence = 1.1 ;
+float max = 1.7 ;
+int niveau = 0 ;
+int tableau [100];
+int i;
+int k;
+int moyenne  = 0;
+char c ;
+
+void acquisition()
+{
+         f=3.3*ain.read();
+         niveau = 100* (f-silence)/max ;
+         tableau[k]= niveau ;
+         k++ ;
+         if (k ==100)
+         {k =0 ;}
+}
+
+
+int moyAboiement()
+{int somme = 0 ;
+int moyenne = 0 ;
+for (i=0;i<100; i++)
+{
+somme = somme + tableau[i];
+}
+moyenne  = somme /100 ;
+
+return moyenne ;
+}
+
+
+int main() {
+     Ticker horloge; 
+     horloge.attach(&acquisition, 0.01);
+     while(1)
+    {    
+      printf("\nSaisir A pour connaitre niveau aboiement \n\r");
+      c = pc.getc() ;
+      if (c=='A')
+      {moyenne = moyAboiement() ;
+       printf("Niveau aboiement sur 1s = %d \n\r", moyenne );
+       }
+      
+    }
+}