Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
fonctions.cpp@2:86f6d5733ae7, 2019-06-11 (annotated)
- Committer:
- achille
- Date:
- Tue Jun 11 11:49:26 2019 +0000
- Revision:
- 2:86f6d5733ae7
- Parent:
- 1:3f5287e5fa3c
volatile ?
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
achille | 2:86f6d5733ae7 | 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 | 2:86f6d5733ae7 | 91 | float pvmax(donnees *t){ |
achille | 2:86f6d5733ae7 | 92 | float max=0,tt=0; |
achille | 2:86f6d5733ae7 | 93 | int f1=0,f2=0; |
achille | 2:86f6d5733ae7 | 94 | for(int i=0;i<REC;i++){ |
achille | 2:86f6d5733ae7 | 95 | if(t[i].V>max){ |
achille | 2:86f6d5733ae7 | 96 | max=t[i].V; |
achille | 2:86f6d5733ae7 | 97 | } |
achille | 2:86f6d5733ae7 | 98 | } |
achille | 2:86f6d5733ae7 | 99 | int j=0; |
achille | 2:86f6d5733ae7 | 100 | float t1=0,t2=0; |
achille | 2:86f6d5733ae7 | 101 | while(f2==0){ |
achille | 2:86f6d5733ae7 | 102 | if((t[j].V>(max-(float)0.2))&&f1==0){ |
achille | 2:86f6d5733ae7 | 103 | t1=t[j].T; |
achille | 2:86f6d5733ae7 | 104 | f1=1; |
achille | 2:86f6d5733ae7 | 105 | } |
achille | 2:86f6d5733ae7 | 106 | else{if((t[j].V>(max-(float)0.2))&&f2==0){ |
achille | 2:86f6d5733ae7 | 107 | t2=t[j].T; |
achille | 2:86f6d5733ae7 | 108 | f2=1; |
achille | 2:86f6d5733ae7 | 109 | } |
achille | 2:86f6d5733ae7 | 110 | } |
achille | 2:86f6d5733ae7 | 111 | j++; |
achille | 2:86f6d5733ae7 | 112 | } |
achille | 2:86f6d5733ae7 | 113 | tt=t2-t1; |
achille | 2:86f6d5733ae7 | 114 | return tt; |
achille | 2:86f6d5733ae7 | 115 | } |
achille | 2:86f6d5733ae7 | 116 | |
achille | 2:86f6d5733ae7 | 117 | |
achille | 1:3f5287e5fa3c | 118 | void affichage(float fIn,float fV, int *flagV, int *flagR1, int *flagR2){ |
achille | 0:608629a8a61c | 119 | *flagV=0; |
achille | 0:608629a8a61c | 120 | *flagR1=0; |
achille | 0:608629a8a61c | 121 | *flagR2=0; |
achille | 0:608629a8a61c | 122 | if(fV-4<fIn && fIn<fV+4){ |
achille | 0:608629a8a61c | 123 | *flagV=1; |
achille | 0:608629a8a61c | 124 | } |
achille | 0:608629a8a61c | 125 | else{ |
achille | 0:608629a8a61c | 126 | if(fV-1>fIn){ |
achille | 0:608629a8a61c | 127 | *flagR2=1; |
achille | 0:608629a8a61c | 128 | } |
achille | 0:608629a8a61c | 129 | else{ |
achille | 0:608629a8a61c | 130 | if(fIn>fV+1){ |
achille | 0:608629a8a61c | 131 | *flagR1=1; |
achille | 0:608629a8a61c | 132 | } |
achille | 0:608629a8a61c | 133 | } |
achille | 0:608629a8a61c | 134 | } |
achille | 0:608629a8a61c | 135 | } |
achille | 0:608629a8a61c | 136 | |
achille | 0:608629a8a61c | 137 | float frequ(float fIn){ |
achille | 0:608629a8a61c | 138 | DigitalOut MI1(D10); |
achille | 0:608629a8a61c | 139 | DigitalOut LA(D9); |
achille | 0:608629a8a61c | 140 | DigitalOut RE(D8); |
achille | 0:608629a8a61c | 141 | DigitalOut SOL(D7); |
achille | 0:608629a8a61c | 142 | DigitalOut SI(D6); |
achille | 0:608629a8a61c | 143 | DigitalOut MI2(D5); |
achille | 0:608629a8a61c | 144 | |
achille | 0:608629a8a61c | 145 | MI1=0; |
achille | 0:608629a8a61c | 146 | LA=0; |
achille | 0:608629a8a61c | 147 | RE=0; |
achille | 0:608629a8a61c | 148 | SOL=0; |
achille | 0:608629a8a61c | 149 | SI=0; |
achille | 0:608629a8a61c | 150 | MI2=0; |
achille | 0:608629a8a61c | 151 | |
achille | 1:3f5287e5fa3c | 152 | if(fIn<(float)96.2){ |
achille | 0:608629a8a61c | 153 | MI1=1; |
achille | 0:608629a8a61c | 154 | return 82.4; |
achille | 0:608629a8a61c | 155 | } |
achille | 1:3f5287e5fa3c | 156 | if(fIn>(float)96.2 && fIn<(float)128.4){ |
achille | 0:608629a8a61c | 157 | LA=1; |
achille | 0:608629a8a61c | 158 | return 110; |
achille | 0:608629a8a61c | 159 | } |
achille | 1:3f5287e5fa3c | 160 | if(fIn>(float)128.4 && fIn<(float)171.4){ |
achille | 0:608629a8a61c | 161 | RE=1; |
achille | 0:608629a8a61c | 162 | return 146.8; |
achille | 0:608629a8a61c | 163 | } |
achille | 1:3f5287e5fa3c | 164 | if(fIn>(float)171.4 && fIn<(float)221.45){ |
achille | 0:608629a8a61c | 165 | SOL=1; |
achille | 0:608629a8a61c | 166 | return 196; |
achille | 0:608629a8a61c | 167 | } |
achille | 1:3f5287e5fa3c | 168 | if(fIn>(float)221.45 && fIn<(float)288.25){ |
achille | 0:608629a8a61c | 169 | SI=1; |
achille | 0:608629a8a61c | 170 | return 246.9; |
achille | 0:608629a8a61c | 171 | } |
achille | 1:3f5287e5fa3c | 172 | if(fIn>(float)288.25){ |
achille | 1:3f5287e5fa3c | 173 | MI2=1; |
achille | 0:608629a8a61c | 174 | return 329.6; |
achille | 0:608629a8a61c | 175 | } |
achille | 0:608629a8a61c | 176 | else{ |
achille | 0:608629a8a61c | 177 | MI1=1; |
achille | 0:608629a8a61c | 178 | LA=1; |
achille | 0:608629a8a61c | 179 | RE=1; |
achille | 0:608629a8a61c | 180 | SOL=1; |
achille | 0:608629a8a61c | 181 | SI=1; |
achille | 0:608629a8a61c | 182 | MI2=1; |
achille | 0:608629a8a61c | 183 | return 0; |
achille | 0:608629a8a61c | 184 | } |
achille | 0:608629a8a61c | 185 | } |
achille | 0:608629a8a61c | 186 | |
achille | 0:608629a8a61c | 187 | |
achille | 0:608629a8a61c | 188 | |
achille | 0:608629a8a61c | 189 | |
achille | 0:608629a8a61c | 190 | |
achille | 0:608629a8a61c | 191 | |
achille | 0:608629a8a61c | 192 | |
achille | 0:608629a8a61c | 193 | |
achille | 0:608629a8a61c | 194 | |
achille | 0:608629a8a61c | 195 | |
achille | 0:608629a8a61c | 196 |