Chrono pour mesurer vitesse pour 1 tour (capteur analogique)

Dependencies:   mbed

Committer:
alainpegatoquet
Date:
Tue Nov 28 09:45:23 2017 +0000
Revision:
0:cf0fbe1e01d4
Child:
1:d5f22105a691
Validation du capteur IR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alainpegatoquet 0:cf0fbe1e01d4 1 #include "mbed.h"
alainpegatoquet 0:cf0fbe1e01d4 2
alainpegatoquet 0:cf0fbe1e01d4 3 // Global variables
alainpegatoquet 0:cf0fbe1e01d4 4 Serial pc(USBTX, USBRX);
alainpegatoquet 0:cf0fbe1e01d4 5 AnalogIn Ain(A3);
alainpegatoquet 0:cf0fbe1e01d4 6 Timer timer1;
alainpegatoquet 0:cf0fbe1e01d4 7
alainpegatoquet 0:cf0fbe1e01d4 8 float IrSensor;
alainpegatoquet 0:cf0fbe1e01d4 9 // Prototype
alainpegatoquet 0:cf0fbe1e01d4 10 float distance(float);
alainpegatoquet 0:cf0fbe1e01d4 11
alainpegatoquet 0:cf0fbe1e01d4 12 // main function
alainpegatoquet 0:cf0fbe1e01d4 13 int main(void)
alainpegatoquet 0:cf0fbe1e01d4 14 {
alainpegatoquet 0:cf0fbe1e01d4 15 pc.printf("Debut du programme...\n");
alainpegatoquet 0:cf0fbe1e01d4 16
alainpegatoquet 0:cf0fbe1e01d4 17 while(1) {
alainpegatoquet 0:cf0fbe1e01d4 18 IrSensor=Ain.read(); // IrSensor belongs to [0.0; 1.0]
alainpegatoquet 0:cf0fbe1e01d4 19 pc.printf("%f \n\r",IrSensor*3.3); // Output voltage from 0 to 3.3V
alainpegatoquet 0:cf0fbe1e01d4 20
alainpegatoquet 0:cf0fbe1e01d4 21 pc.printf("Distance en cm : %.1f \n\r",distance(IrSensor*3.3));
alainpegatoquet 0:cf0fbe1e01d4 22 wait (0.5);
alainpegatoquet 0:cf0fbe1e01d4 23 }
alainpegatoquet 0:cf0fbe1e01d4 24 }
alainpegatoquet 0:cf0fbe1e01d4 25
alainpegatoquet 0:cf0fbe1e01d4 26 // Calcul de la distance
alainpegatoquet 0:cf0fbe1e01d4 27 // Entre 20 et 80cm, on peut approximer la distance avec r=24/(V-0,1)
alainpegatoquet 0:cf0fbe1e01d4 28 // r = distance en cm
alainpegatoquet 0:cf0fbe1e01d4 29 // V = tension lue
alainpegatoquet 0:cf0fbe1e01d4 30 float distance(float tension)
alainpegatoquet 0:cf0fbe1e01d4 31 {
alainpegatoquet 0:cf0fbe1e01d4 32 return(24.0/(tension - 0.1));
alainpegatoquet 0:cf0fbe1e01d4 33 }
alainpegatoquet 0:cf0fbe1e01d4 34