![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
programme accordeur guitare valide
fonctions.cpp@0:608629a8a61c, 2019-06-05 (annotated)
- Committer:
- achille
- Date:
- Wed Jun 05 09:40:07 2019 +0000
- Revision:
- 0:608629a8a61c
- Child:
- 1:3f5287e5fa3c
avec les notes ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
achille | 0:608629a8a61c | 1 | #include"fonctions.h" |
achille | 0:608629a8a61c | 2 | |
achille | 0:608629a8a61c | 3 | |
achille | 0:608629a8a61c | 4 | void led_set(int flagV, int flagR1,int flagR2) |
achille | 0:608629a8a61c | 5 | { |
achille | 0:608629a8a61c | 6 | DigitalOut ledV(D13); |
achille | 0:608629a8a61c | 7 | DigitalOut ledR1(D12); |
achille | 0:608629a8a61c | 8 | DigitalOut ledR2(D11); |
achille | 0:608629a8a61c | 9 | |
achille | 0:608629a8a61c | 10 | if(flagV) { |
achille | 0:608629a8a61c | 11 | ledV=1; |
achille | 0:608629a8a61c | 12 | } else { |
achille | 0:608629a8a61c | 13 | ledV=0; |
achille | 0:608629a8a61c | 14 | } |
achille | 0:608629a8a61c | 15 | if(flagR1) { |
achille | 0:608629a8a61c | 16 | ledR1=1; |
achille | 0:608629a8a61c | 17 | } else { |
achille | 0:608629a8a61c | 18 | ledR1.write(0); |
achille | 0:608629a8a61c | 19 | } |
achille | 0:608629a8a61c | 20 | if(flagR2) { |
achille | 0:608629a8a61c | 21 | ledR2=1; |
achille | 0:608629a8a61c | 22 | } else { |
achille | 0:608629a8a61c | 23 | ledR2=0; |
achille | 0:608629a8a61c | 24 | } |
achille | 0:608629a8a61c | 25 | } |
achille | 0:608629a8a61c | 26 | |
achille | 0:608629a8a61c | 27 | void recup(volatile donnees *t, float time, int i){ |
achille | 0:608629a8a61c | 28 | AnalogIn mic(A5); |
achille | 0:608629a8a61c | 29 | |
achille | 0:608629a8a61c | 30 | float v = mic.read(); |
achille | 0:608629a8a61c | 31 | |
achille | 0:608629a8a61c | 32 | t[i].T=time; |
achille | 0:608629a8a61c | 33 | t[i].V=v; |
achille | 0:608629a8a61c | 34 | |
achille | 0:608629a8a61c | 35 | } |
achille | 0:608629a8a61c | 36 | |
achille | 0:608629a8a61c | 37 | float moy(volatile donnees *t){ |
achille | 0:608629a8a61c | 38 | float moy=0; |
achille | 0:608629a8a61c | 39 | for(int i=0;i<REC;i++){ |
achille | 0:608629a8a61c | 40 | moy += t[i].V; |
achille | 0:608629a8a61c | 41 | } |
achille | 0:608629a8a61c | 42 | moy = moy/REC; |
achille | 0:608629a8a61c | 43 | |
achille | 0:608629a8a61c | 44 | return moy; |
achille | 0:608629a8a61c | 45 | } |
achille | 0:608629a8a61c | 46 | |
achille | 0:608629a8a61c | 47 | float period(volatile donnees *t, float mo){ |
achille | 0:608629a8a61c | 48 | int flagh=0,i=0; |
achille | 0:608629a8a61c | 49 | float t1,t2; |
achille | 0:608629a8a61c | 50 | if(t[i].V> mo ){ |
achille | 0:608629a8a61c | 51 | flagh=1; |
achille | 0:608629a8a61c | 52 | while(flagh==1){ |
achille | 0:608629a8a61c | 53 | if(t[i].V<mo){ |
achille | 0:608629a8a61c | 54 | flagh=0; |
achille | 0:608629a8a61c | 55 | } |
achille | 0:608629a8a61c | 56 | else{ |
achille | 0:608629a8a61c | 57 | i++; |
achille | 0:608629a8a61c | 58 | } |
achille | 0:608629a8a61c | 59 | } |
achille | 0:608629a8a61c | 60 | } |
achille | 0:608629a8a61c | 61 | while(flagh==0){ |
achille | 0:608629a8a61c | 62 | if(t[i].V>mo){ |
achille | 0:608629a8a61c | 63 | flagh=1; |
achille | 0:608629a8a61c | 64 | } |
achille | 0:608629a8a61c | 65 | else{ |
achille | 0:608629a8a61c | 66 | i++; |
achille | 0:608629a8a61c | 67 | } |
achille | 0:608629a8a61c | 68 | } |
achille | 0:608629a8a61c | 69 | t1=t[i].T; |
achille | 0:608629a8a61c | 70 | while(flagh==1){ |
achille | 0:608629a8a61c | 71 | if(t[i].V<mo){ |
achille | 0:608629a8a61c | 72 | flagh=0; |
achille | 0:608629a8a61c | 73 | } |
achille | 0:608629a8a61c | 74 | else{ |
achille | 0:608629a8a61c | 75 | i++; |
achille | 0:608629a8a61c | 76 | } |
achille | 0:608629a8a61c | 77 | } |
achille | 0:608629a8a61c | 78 | while(flagh==0){ |
achille | 0:608629a8a61c | 79 | if(t[i].V>mo){ |
achille | 0:608629a8a61c | 80 | flagh=1; |
achille | 0:608629a8a61c | 81 | } |
achille | 0:608629a8a61c | 82 | else{ |
achille | 0:608629a8a61c | 83 | i++; |
achille | 0:608629a8a61c | 84 | } |
achille | 0:608629a8a61c | 85 | } |
achille | 0:608629a8a61c | 86 | t2=t[i].T; |
achille | 0:608629a8a61c | 87 | |
achille | 0:608629a8a61c | 88 | return t2-t1; |
achille | 0:608629a8a61c | 89 | } |
achille | 0:608629a8a61c | 90 | |
achille | 0:608629a8a61c | 91 | void affichage(float fIn,float +fV, int *flagV, int *flagR1, int *flagR2){ |
achille | 0:608629a8a61c | 92 | *flagV=0; |
achille | 0:608629a8a61c | 93 | *flagR1=0; |
achille | 0:608629a8a61c | 94 | *flagR2=0; |
achille | 0:608629a8a61c | 95 | if(fV-4<fIn && fIn<fV+4){ |
achille | 0:608629a8a61c | 96 | *flagV=1; |
achille | 0:608629a8a61c | 97 | } |
achille | 0:608629a8a61c | 98 | else{ |
achille | 0:608629a8a61c | 99 | if(fV-1>fIn){ |
achille | 0:608629a8a61c | 100 | *flagR2=1; |
achille | 0:608629a8a61c | 101 | } |
achille | 0:608629a8a61c | 102 | else{ |
achille | 0:608629a8a61c | 103 | if(fIn>fV+1){ |
achille | 0:608629a8a61c | 104 | *flagR1=1; |
achille | 0:608629a8a61c | 105 | } |
achille | 0:608629a8a61c | 106 | } |
achille | 0:608629a8a61c | 107 | } |
achille | 0:608629a8a61c | 108 | } |
achille | 0:608629a8a61c | 109 | |
achille | 0:608629a8a61c | 110 | float frequ(float fIn){ |
achille | 0:608629a8a61c | 111 | DigitalOut MI1(D10); |
achille | 0:608629a8a61c | 112 | DigitalOut LA(D9); |
achille | 0:608629a8a61c | 113 | DigitalOut RE(D8); |
achille | 0:608629a8a61c | 114 | DigitalOut SOL(D7); |
achille | 0:608629a8a61c | 115 | DigitalOut SI(D6); |
achille | 0:608629a8a61c | 116 | DigitalOut MI2(D5); |
achille | 0:608629a8a61c | 117 | |
achille | 0:608629a8a61c | 118 | MI1=0; |
achille | 0:608629a8a61c | 119 | LA=0; |
achille | 0:608629a8a61c | 120 | RE=0; |
achille | 0:608629a8a61c | 121 | SOL=0; |
achille | 0:608629a8a61c | 122 | SI=0; |
achille | 0:608629a8a61c | 123 | MI2=0; |
achille | 0:608629a8a61c | 124 | |
achille | 0:608629a8a61c | 125 | if(fIn<96.2){ |
achille | 0:608629a8a61c | 126 | MI1=1; |
achille | 0:608629a8a61c | 127 | return 82.4; |
achille | 0:608629a8a61c | 128 | } |
achille | 0:608629a8a61c | 129 | if(fIn>96.2 && fIn<128.4){ |
achille | 0:608629a8a61c | 130 | LA=1; |
achille | 0:608629a8a61c | 131 | return 110; |
achille | 0:608629a8a61c | 132 | } |
achille | 0:608629a8a61c | 133 | if(fIn>128.4 && fIn<171.4){ |
achille | 0:608629a8a61c | 134 | RE=1; |
achille | 0:608629a8a61c | 135 | return 146.8; |
achille | 0:608629a8a61c | 136 | } |
achille | 0:608629a8a61c | 137 | if(fIn>171.4 && fIn<221.45){ |
achille | 0:608629a8a61c | 138 | SOL=1; |
achille | 0:608629a8a61c | 139 | return 196; |
achille | 0:608629a8a61c | 140 | } |
achille | 0:608629a8a61c | 141 | if(fIn>221.45 && fIn<288.25){ |
achille | 0:608629a8a61c | 142 | SI=1; |
achille | 0:608629a8a61c | 143 | return 246.9; |
achille | 0:608629a8a61c | 144 | } |
achille | 0:608629a8a61c | 145 | if(fIn>288.25){ |
achille | 0:608629a8a61c | 146 | MI2=1 |
achille | 0:608629a8a61c | 147 | return 329.6; |
achille | 0:608629a8a61c | 148 | } |
achille | 0:608629a8a61c | 149 | else{ |
achille | 0:608629a8a61c | 150 | MI1=1; |
achille | 0:608629a8a61c | 151 | LA=1; |
achille | 0:608629a8a61c | 152 | RE=1; |
achille | 0:608629a8a61c | 153 | SOL=1; |
achille | 0:608629a8a61c | 154 | SI=1; |
achille | 0:608629a8a61c | 155 | MI2=1; |
achille | 0:608629a8a61c | 156 | return 0; |
achille | 0:608629a8a61c | 157 | } |
achille | 0:608629a8a61c | 158 | } |
achille | 0:608629a8a61c | 159 | |
achille | 0:608629a8a61c | 160 | |
achille | 0:608629a8a61c | 161 | |
achille | 0:608629a8a61c | 162 | |
achille | 0:608629a8a61c | 163 | |
achille | 0:608629a8a61c | 164 | |
achille | 0:608629a8a61c | 165 | |
achille | 0:608629a8a61c | 166 | |
achille | 0:608629a8a61c | 167 | |
achille | 0:608629a8a61c | 168 | |
achille | 0:608629a8a61c | 169 |