Mesure sur 1 seconde avec moyenneage

Dependencies:   mbed

Committer:
the420team
Date:
Tue May 22 07:37:57 2018 +0000
Revision:
0:14c42a61cdb2
Programme detection aboiement moyenne 1 s

Who changed what in which revision?

UserRevisionLine numberNew contents of line
the420team 0:14c42a61cdb2 1 #include "mbed.h"
the420team 0:14c42a61cdb2 2
the420team 0:14c42a61cdb2 3 Serial pc (USBTX, USBRX);
the420team 0:14c42a61cdb2 4 AnalogIn ain(p17);
the420team 0:14c42a61cdb2 5 DigitalOut led(p7);
the420team 0:14c42a61cdb2 6
the420team 0:14c42a61cdb2 7 float f ;
the420team 0:14c42a61cdb2 8 float silence = 1.1 ;
the420team 0:14c42a61cdb2 9 float max = 1.7 ;
the420team 0:14c42a61cdb2 10 int niveau = 0 ;
the420team 0:14c42a61cdb2 11 int tableau [100];
the420team 0:14c42a61cdb2 12 int i;
the420team 0:14c42a61cdb2 13 int k;
the420team 0:14c42a61cdb2 14 int moyenne = 0;
the420team 0:14c42a61cdb2 15 char c ;
the420team 0:14c42a61cdb2 16
the420team 0:14c42a61cdb2 17 void acquisition()
the420team 0:14c42a61cdb2 18 {
the420team 0:14c42a61cdb2 19 f=3.3*ain.read();
the420team 0:14c42a61cdb2 20 niveau = 100* (f-silence)/max ;
the420team 0:14c42a61cdb2 21 tableau[k]= niveau ;
the420team 0:14c42a61cdb2 22 k++ ;
the420team 0:14c42a61cdb2 23 if (k ==100)
the420team 0:14c42a61cdb2 24 {k =0 ;}
the420team 0:14c42a61cdb2 25 }
the420team 0:14c42a61cdb2 26
the420team 0:14c42a61cdb2 27
the420team 0:14c42a61cdb2 28 int moyAboiement()
the420team 0:14c42a61cdb2 29 {int somme = 0 ;
the420team 0:14c42a61cdb2 30 int moyenne = 0 ;
the420team 0:14c42a61cdb2 31 for (i=0;i<100; i++)
the420team 0:14c42a61cdb2 32 {
the420team 0:14c42a61cdb2 33 somme = somme + tableau[i];
the420team 0:14c42a61cdb2 34 }
the420team 0:14c42a61cdb2 35 moyenne = somme /100 ;
the420team 0:14c42a61cdb2 36
the420team 0:14c42a61cdb2 37 return moyenne ;
the420team 0:14c42a61cdb2 38 }
the420team 0:14c42a61cdb2 39
the420team 0:14c42a61cdb2 40
the420team 0:14c42a61cdb2 41 int main() {
the420team 0:14c42a61cdb2 42 Ticker horloge;
the420team 0:14c42a61cdb2 43 horloge.attach(&acquisition, 0.01);
the420team 0:14c42a61cdb2 44 while(1)
the420team 0:14c42a61cdb2 45 {
the420team 0:14c42a61cdb2 46 printf("\nSaisir A pour connaitre niveau aboiement \n\r");
the420team 0:14c42a61cdb2 47 c = pc.getc() ;
the420team 0:14c42a61cdb2 48 if (c=='A')
the420team 0:14c42a61cdb2 49 {moyenne = moyAboiement() ;
the420team 0:14c42a61cdb2 50 printf("Niveau aboiement sur 1s = %d \n\r", moyenne );
the420team 0:14c42a61cdb2 51 }
the420team 0:14c42a61cdb2 52
the420team 0:14c42a61cdb2 53 }
the420team 0:14c42a61cdb2 54 }