app6
Dependencies: mbed
Revision 1:770d7fd69e4f, committed 2014-04-01
- Comitter:
- joGenie
- Date:
- Tue Apr 01 14:08:27 2014 +0000
- Parent:
- 0:ac91697dd6e0
- Commit message:
- New Version;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r ac91697dd6e0 -r 770d7fd69e4f main.cpp --- a/main.cpp Tue Apr 01 13:20:48 2014 +0000 +++ b/main.cpp Tue Apr 01 14:08:27 2014 +0000 @@ -3,6 +3,18 @@ AnalogIn in(p20); Serial pc(USBTX, USBRX); +double facteur[6] = { 111.38, 0.1759, 0.0002, -1*pow(10, -7), 4*pow(10, -11), -4*pow(10, -15) } + +unsigned short calculDistance(unsigned short volt) +{ + unsigned short distance; + + for (int i = 0; i < 5; i++) + distance += facteur[i]*pow(volt, i); + + return distance; +} + int main() { unsigned short volt; @@ -11,7 +23,7 @@ while(1) { volt = in.read_u16(); - d = -4*pow(10, -15)*pow(volt, 5) + 4*pow(10, -11)*pow(volt, 4) - 1*pow(10, -7)*pow(volt, 3) + 0.0002*pow(volt, 2) - 0.1759*volt + 111.38; + d = calculDistance(volt); pc.printf("V: %d, d: %d", volt, d); wait(0.1); }