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.
Dependencies: mbed
Fork of IrSensorDistanceMessure by
main.cpp
- Committer:
- ahlervin
- Date:
- 2018-05-06
- Revision:
- 0:a49ea5211c34
- Child:
- 1:8184ab7e4395
File content as of revision 0:a49ea5211c34:
#include "mbed.h"
//Distandce Messure IR Sensor
//Meas = f(s)
AnalogIn analog_value(PC_3);
AnalogIn analog_value2(PC_5);
const float PR1 = 3.4734*0.000000001; //Koeffizienten
const float PR2 = -7.1846*0.000001;
const float PR3 = 0.0055;
const float PR4 = -1.9304;
const float PR5 = 301.2428;
const float PL1 = 3.4734*0.000000001;
const float PL2 = -7.1846*0.000001;
const float PL3 = 0.0055;
const float PL4 = -1.9304;
const float PL5 = 301.2428;
float disL;
float disR;
int roundL;
int roundR;
int main() {
float measL;
float measR;
printf("\nDistance Test Sensoren Rechts und Links\n");
printf("misst die Distanz vom Wagenrad bis Objekt\n");
wait(1.5);
while(1) {
measR = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
measR = measR * 1000; // Change the value to be in the 0 to 1000 range
disR = PR1*pow(measR,4)+PR2*pow(measR,3)+PR3*pow(measR,2)+PR4*measR+PR5; //disR = f(measR)
roundR = disR*100;
disR = roundR/100.0-10.0;
printf("Distanz R = %f\n", disR);
measL = analog_value2.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
measL = measL * 1000; // Change the value to be in the 0 to 1000 range
disL = PL1*pow(measL,4)+PL2*pow(measL,3)+PL3*pow(measL,2)+PL4*measL+PL5; //disL = f(measL)
roundL = disL*100;
disL = roundL/100.0-10.0;
printf("Distanz L = %f\n", disL);
wait(0.7); // 1 s
}
}
