Modifier les valeurs seuils selon l'environnement
Dependencies: mbed
main.cpp@0:835360b27a84, 2016-06-10 (annotated)
- Committer:
- GuiguiZizouniet
- Date:
- Fri Jun 10 13:55:09 2016 +0000
- Revision:
- 0:835360b27a84
Test distance
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GuiguiZizouniet | 0:835360b27a84 | 1 | #include "mbed.h" |
GuiguiZizouniet | 0:835360b27a84 | 2 | |
GuiguiZizouniet | 0:835360b27a84 | 3 | |
GuiguiZizouniet | 0:835360b27a84 | 4 | |
GuiguiZizouniet | 0:835360b27a84 | 5 | AnalogIn entree (A0); |
GuiguiZizouniet | 0:835360b27a84 | 6 | float prise, inverse_distance; |
GuiguiZizouniet | 0:835360b27a84 | 7 | int valeur_seuil_min=400; |
GuiguiZizouniet | 0:835360b27a84 | 8 | int valeur_seuil_max=500; |
GuiguiZizouniet | 0:835360b27a84 | 9 | |
GuiguiZizouniet | 0:835360b27a84 | 10 | |
GuiguiZizouniet | 0:835360b27a84 | 11 | |
GuiguiZizouniet | 0:835360b27a84 | 12 | float moyenne() { |
GuiguiZizouniet | 0:835360b27a84 | 13 | |
GuiguiZizouniet | 0:835360b27a84 | 14 | float i=0; |
GuiguiZizouniet | 0:835360b27a84 | 15 | float valeur, total, moyenne; |
GuiguiZizouniet | 0:835360b27a84 | 16 | |
GuiguiZizouniet | 0:835360b27a84 | 17 | valeur=entree.read()*1000; |
GuiguiZizouniet | 0:835360b27a84 | 18 | |
GuiguiZizouniet | 0:835360b27a84 | 19 | while(valeur>valeur_seuil_min) { |
GuiguiZizouniet | 0:835360b27a84 | 20 | valeur=entree.read()*1000; |
GuiguiZizouniet | 0:835360b27a84 | 21 | i=i+1; |
GuiguiZizouniet | 0:835360b27a84 | 22 | total=total+valeur; |
GuiguiZizouniet | 0:835360b27a84 | 23 | } |
GuiguiZizouniet | 0:835360b27a84 | 24 | moyenne=total/i; |
GuiguiZizouniet | 0:835360b27a84 | 25 | return moyenne; |
GuiguiZizouniet | 0:835360b27a84 | 26 | } |
GuiguiZizouniet | 0:835360b27a84 | 27 | |
GuiguiZizouniet | 0:835360b27a84 | 28 | |
GuiguiZizouniet | 0:835360b27a84 | 29 | |
GuiguiZizouniet | 0:835360b27a84 | 30 | int main() { |
GuiguiZizouniet | 0:835360b27a84 | 31 | while(1) { |
GuiguiZizouniet | 0:835360b27a84 | 32 | prise=entree.read()*1000; |
GuiguiZizouniet | 0:835360b27a84 | 33 | if (prise>valeur_seuil_max); |
GuiguiZizouniet | 0:835360b27a84 | 34 | inverse_distance=moyenne(); |
GuiguiZizouniet | 0:835360b27a84 | 35 | printf("%f\n", inverse_distance); |
GuiguiZizouniet | 0:835360b27a84 | 36 | } |
GuiguiZizouniet | 0:835360b27a84 | 37 | } |
GuiguiZizouniet | 0:835360b27a84 | 38 |