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@1:8184ab7e4395, 2018-05-06 (annotated)
- Committer:
- ahlervin
- Date:
- Sun May 06 12:50:45 2018 +0000
- Revision:
- 1:8184ab7e4395
- Parent:
- 0:a49ea5211c34
Testen vom Polynom IR Front
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ahlervin | 0:a49ea5211c34 | 1 | #include "mbed.h" |
| ahlervin | 0:a49ea5211c34 | 2 | |
| ahlervin | 0:a49ea5211c34 | 3 | //Distandce Messure IR Sensor |
| ahlervin | 0:a49ea5211c34 | 4 | //Meas = f(s) |
| ahlervin | 0:a49ea5211c34 | 5 | |
| ahlervin | 1:8184ab7e4395 | 6 | AnalogIn analog_value(PC_2); |
| ahlervin | 0:a49ea5211c34 | 7 | |
| ahlervin | 1:8184ab7e4395 | 8 | const float PF1 = 6.1767f*pow(10.0f,-10); |
| ahlervin | 1:8184ab7e4395 | 9 | const float PF2 = -1.9975f*pow(10.0f,-6); |
| ahlervin | 1:8184ab7e4395 | 10 | const float PF3 = 0.0024f; |
| ahlervin | 1:8184ab7e4395 | 11 | const float PF4 = -1.3299f; |
| ahlervin | 1:8184ab7e4395 | 12 | const float PF5 = 351.1557f; |
| ahlervin | 1:8184ab7e4395 | 13 | float disF; |
| ahlervin | 1:8184ab7e4395 | 14 | int roundF; |
| ahlervin | 0:a49ea5211c34 | 15 | |
| ahlervin | 0:a49ea5211c34 | 16 | int main() { |
| ahlervin | 1:8184ab7e4395 | 17 | |
| ahlervin | 1:8184ab7e4395 | 18 | float measF; |
| ahlervin | 1:8184ab7e4395 | 19 | printf("\nDistance Test Sensoren Front\n"); |
| ahlervin | 0:a49ea5211c34 | 20 | printf("misst die Distanz vom Wagenrad bis Objekt\n"); |
| ahlervin | 0:a49ea5211c34 | 21 | wait(1.5); |
| ahlervin | 0:a49ea5211c34 | 22 | |
| ahlervin | 0:a49ea5211c34 | 23 | while(1) { |
| ahlervin | 1:8184ab7e4395 | 24 | |
| ahlervin | 0:a49ea5211c34 | 25 | |
| ahlervin | 1:8184ab7e4395 | 26 | measF = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
| ahlervin | 1:8184ab7e4395 | 27 | measF = measF * 1000; // Change the value to be in the 0 to 1000 range |
| ahlervin | 1:8184ab7e4395 | 28 | disF = PF1*pow(measF,4)+PF2*pow(measF,3)+PF3*pow(measF,2)+PF4*measF+PF5; //disF = f(measF) |
| ahlervin | 1:8184ab7e4395 | 29 | roundF = disF*100; |
| ahlervin | 1:8184ab7e4395 | 30 | disF = roundF/100.0-20.0; |
| ahlervin | 0:a49ea5211c34 | 31 | |
| ahlervin | 1:8184ab7e4395 | 32 | printf("Distanz Front = %f\n", disF); |
| ahlervin | 0:a49ea5211c34 | 33 | |
| ahlervin | 0:a49ea5211c34 | 34 | wait(0.7); // 1 s |
| ahlervin | 0:a49ea5211c34 | 35 | } |
| ahlervin | 0:a49ea5211c34 | 36 | } |
