programme accordeur guitare valide

Dependencies:   mbed USBDevice

Committer:
achille
Date:
Tue Jun 11 11:49:26 2019 +0000
Revision:
2:86f6d5733ae7
Parent:
0:608629a8a61c
volatile ?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
achille 0:608629a8a61c 1 #include "fonctions.h"
achille 0:608629a8a61c 2
achille 0:608629a8a61c 3 Ticker recupp;
achille 0:608629a8a61c 4 /*USBSerial port;*/
achille 0:608629a8a61c 5 Serial port(USBTX,USBRX,9600);
achille 0:608629a8a61c 6 Timer tps;
achille 0:608629a8a61c 7
achille 0:608629a8a61c 8
achille 0:608629a8a61c 9
achille 2:86f6d5733ae7 10 donnees t[REC];
achille 0:608629a8a61c 11 volatile int i;
achille 0:608629a8a61c 12 volatile int flag;
achille 0:608629a8a61c 13
achille 0:608629a8a61c 14 void here(){
achille 0:608629a8a61c 15 if(i<REC){
achille 0:608629a8a61c 16 recup(t,tps.read(),i);
achille 0:608629a8a61c 17 i++;
achille 0:608629a8a61c 18 }
achille 0:608629a8a61c 19 else{
achille 0:608629a8a61c 20 flag=1;
achille 0:608629a8a61c 21 }
achille 0:608629a8a61c 22 }
achille 0:608629a8a61c 23
achille 0:608629a8a61c 24 int main() {
achille 0:608629a8a61c 25 port.printf("bonjour \r\n ");
achille 0:608629a8a61c 26 int flagV=1, flagR1=1, flagR2=1;
achille 0:608629a8a61c 27 led_set(flagV,flagR1,flagR2);
achille 0:608629a8a61c 28 wait(1);
achille 0:608629a8a61c 29 flag=0;
achille 0:608629a8a61c 30 i=0;
achille 0:608629a8a61c 31 recupp.attach(&here,0.00001);
achille 0:608629a8a61c 32 while(1) {
achille 0:608629a8a61c 33 tps.start();
achille 0:608629a8a61c 34 if(flag==1){
achille 0:608629a8a61c 35 tps.stop();
achille 0:608629a8a61c 36 /* flagV=1;
achille 0:608629a8a61c 37 flagR1=1;
achille 0:608629a8a61c 38 flagR2=1;
achille 0:608629a8a61c 39 led_set(flagV,flagR1,flagR2);
achille 0:608629a8a61c 40 wait(0.5);
achille 0:608629a8a61c 41 flagV=0;
achille 0:608629a8a61c 42 flagR1=0;
achille 0:608629a8a61c 43 flagR2=0;
achille 0:608629a8a61c 44 led_set(flagV,flagR1,flagR2);*/
achille 0:608629a8a61c 45 /*tps.start();
achille 0:608629a8a61c 46 for(int k;k<REC;k++){
achille 0:608629a8a61c 47 recup(t,tps.read(),k);
achille 0:608629a8a61c 48 }
achille 0:608629a8a61c 49 tps.stop();*/
achille 0:608629a8a61c 50 recupp.detach();
achille 2:86f6d5733ae7 51 /*float mo=moy(t);
achille 2:86f6d5733ae7 52 port.printf("la moyenne %f \r\n ",mo);*/
achille 2:86f6d5733ae7 53 float pf=0;
achille 2:86f6d5733ae7 54 pf=pvmax(t);
achille 0:608629a8a61c 55 pf=1/pf;
achille 0:608629a8a61c 56 port.printf("la freq %f\r\n ",pf);
achille 0:608629a8a61c 57 affichage(pf,frequ(pf),&flagV,&flagR1,&flagR2);
achille 0:608629a8a61c 58 led_set(flagV,flagR1,flagR2);
achille 2:86f6d5733ae7 59 /*wait(0.5);*/
achille 2:86f6d5733ae7 60 /*flagV=0;
achille 0:608629a8a61c 61 flagR1=0;
achille 0:608629a8a61c 62 flagR2=0;
achille 2:86f6d5733ae7 63 led_set(flagV,flagR1,flagR2); */
achille 0:608629a8a61c 64 i=0;
achille 0:608629a8a61c 65 flag=0;
achille 0:608629a8a61c 66 tps.start();
achille 0:608629a8a61c 67 recupp.attach(&here,0.00001);
achille 0:608629a8a61c 68 }
achille 0:608629a8a61c 69 }
achille 0:608629a8a61c 70 }
achille 2:86f6d5733ae7 71
achille 2:86f6d5733ae7 72 float toto(donnees *t){
achille 2:86f6d5733ae7 73 float max=0,tt=0;
achille 2:86f6d5733ae7 74 int f1=0,f2=0;
achille 2:86f6d5733ae7 75 for(int i=0;i<REC;i++){
achille 2:86f6d5733ae7 76 if(t[i].V>max){
achille 2:86f6d5733ae7 77 max=t[i].V;
achille 2:86f6d5733ae7 78 }
achille 2:86f6d5733ae7 79 }
achille 2:86f6d5733ae7 80 int j=0;
achille 2:86f6d5733ae7 81 float t1=0,t2=0;
achille 2:86f6d5733ae7 82 while(f2==0){
achille 2:86f6d5733ae7 83 if((t[j].V>(max-(float)0.2))&&f1==0){
achille 2:86f6d5733ae7 84 t1=t[j].T;
achille 2:86f6d5733ae7 85 f1=1;
achille 2:86f6d5733ae7 86 }
achille 2:86f6d5733ae7 87 else{if((t[j].V>(max-(float)0.2))&&f2==0){
achille 2:86f6d5733ae7 88 t2=t[j].T;
achille 2:86f6d5733ae7 89 f2=1;
achille 2:86f6d5733ae7 90 }
achille 2:86f6d5733ae7 91 }
achille 2:86f6d5733ae7 92 j++;
achille 2:86f6d5733ae7 93 }
achille 2:86f6d5733ae7 94 tt=t2-t1;
achille 2:86f6d5733ae7 95 return tt;
achille 2:86f6d5733ae7 96 }