programme accordeur guitare valide

Dependencies:   mbed USBDevice

main.cpp

Committer:
achille
Date:
2019-06-11
Revision:
2:86f6d5733ae7
Parent:
0:608629a8a61c

File content as of revision 2:86f6d5733ae7:

#include "fonctions.h"

Ticker recupp;
/*USBSerial port;*/
Serial port(USBTX,USBRX,9600);
Timer tps;



donnees t[REC];
volatile int i;
volatile int flag;

void here(){
    if(i<REC){
        recup(t,tps.read(),i);
        i++;
        }
    else{
        flag=1;
        }
    }

int main() {
    port.printf("bonjour \r\n ");
    int flagV=1, flagR1=1, flagR2=1;
    led_set(flagV,flagR1,flagR2);
    wait(1);
    flag=0;
    i=0;
    recupp.attach(&here,0.00001);
    while(1) {
        tps.start();
        if(flag==1){
           tps.stop();
           /* flagV=1;
            flagR1=1;
            flagR2=1;
            led_set(flagV,flagR1,flagR2);
            wait(0.5);
            flagV=0;
            flagR1=0;
            flagR2=0;
            led_set(flagV,flagR1,flagR2);*/
            /*tps.start();
            for(int k;k<REC;k++){
                recup(t,tps.read(),k);
                }
            tps.stop();*/
            recupp.detach();
            /*float mo=moy(t);
            port.printf("la moyenne %f \r\n ",mo);*/
            float pf=0;
            pf=pvmax(t);
            pf=1/pf;
            port.printf("la freq %f\r\n ",pf);
            affichage(pf,frequ(pf),&flagV,&flagR1,&flagR2);
            led_set(flagV,flagR1,flagR2);
            /*wait(0.5);*/
            /*flagV=0;
            flagR1=0;
            flagR2=0;
            led_set(flagV,flagR1,flagR2); */           
            i=0;
            flag=0;
            tps.start();
            recupp.attach(&here,0.00001);
            }
    }
}

float toto(donnees *t){
    float max=0,tt=0;
    int f1=0,f2=0;
    for(int i=0;i<REC;i++){
        if(t[i].V>max){
            max=t[i].V;
            }
        }
        int j=0;
        float t1=0,t2=0;
        while(f2==0){
            if((t[j].V>(max-(float)0.2))&&f1==0){
                t1=t[j].T;
                f1=1;
                }
            else{if((t[j].V>(max-(float)0.2))&&f2==0){
                t2=t[j].T;
                f2=1;
                }
            }
            j++;
        }
            tt=t2-t1;
           return tt;
    }