Accordeur
/
accordeurguit
programme accordeur guitare valide
Diff: fonctions.cpp
- Revision:
- 0:608629a8a61c
- Child:
- 1:3f5287e5fa3c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fonctions.cpp Wed Jun 05 09:40:07 2019 +0000 @@ -0,0 +1,169 @@ +#include"fonctions.h" + + +void led_set(int flagV, int flagR1,int flagR2) +{ + DigitalOut ledV(D13); + DigitalOut ledR1(D12); + DigitalOut ledR2(D11); + + if(flagV) { + ledV=1; + } else { + ledV=0; + } + if(flagR1) { + ledR1=1; + } else { + ledR1.write(0); + } + if(flagR2) { + ledR2=1; + } else { + ledR2=0; + } +} + +void recup(volatile donnees *t, float time, int i){ + AnalogIn mic(A5); + + float v = mic.read(); + + t[i].T=time; + t[i].V=v; + + } + +float moy(volatile donnees *t){ + float moy=0; + for(int i=0;i<REC;i++){ + moy += t[i].V; + } + moy = moy/REC; + + return moy; + } + +float period(volatile donnees *t, float mo){ + int flagh=0,i=0; + float t1,t2; + if(t[i].V> mo ){ + flagh=1; + while(flagh==1){ + if(t[i].V<mo){ + flagh=0; + } + else{ + i++; + } + } + } + while(flagh==0){ + if(t[i].V>mo){ + flagh=1; + } + else{ + i++; + } + } + t1=t[i].T; + while(flagh==1){ + if(t[i].V<mo){ + flagh=0; + } + else{ + i++; + } + } + while(flagh==0){ + if(t[i].V>mo){ + flagh=1; + } + else{ + i++; + } + } + t2=t[i].T; + + return t2-t1; + } + +void affichage(float fIn,float +fV, int *flagV, int *flagR1, int *flagR2){ + *flagV=0; + *flagR1=0; + *flagR2=0; + if(fV-4<fIn && fIn<fV+4){ + *flagV=1; + } + else{ + if(fV-1>fIn){ + *flagR2=1; + } + else{ + if(fIn>fV+1){ + *flagR1=1; + } + } + } + } + +float frequ(float fIn){ + DigitalOut MI1(D10); + DigitalOut LA(D9); + DigitalOut RE(D8); + DigitalOut SOL(D7); + DigitalOut SI(D6); + DigitalOut MI2(D5); + + MI1=0; + LA=0; + RE=0; + SOL=0; + SI=0; + MI2=0; + + if(fIn<96.2){ + MI1=1; + return 82.4; + } + if(fIn>96.2 && fIn<128.4){ + LA=1; + return 110; + } + if(fIn>128.4 && fIn<171.4){ + RE=1; + return 146.8; + } + if(fIn>171.4 && fIn<221.45){ + SOL=1; + return 196; + } + if(fIn>221.45 && fIn<288.25){ + SI=1; + return 246.9; + } + if(fIn>288.25){ + MI2=1 + return 329.6; + } + else{ + MI1=1; + LA=1; + RE=1; + SOL=1; + SI=1; + MI2=1; + return 0; + } + } + + + + + + + + + + + \ No newline at end of file