Basic library for Pololu's Sharp GP2Y0A51SK0F

Dependencies:   mbed

Dependents:   GrabTest R5 2016 Robotics Team 1

Revision:
0:d03df6dd14d6
Child:
1:8db052ec94f1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DistanceSensor.cpp	Wed Apr 06 23:02:33 2016 +0000
@@ -0,0 +1,12 @@
+#include "DistanceSensor.h"
+#include <cmath>
+
+DistanceSensor::DistanceSensor(PinName ai) : voltage(ai) {}
+
+float DistanceSensor::getDistance()
+{   
+    float v = voltage.read();
+    //calibration curve for 2
+    return 1044.8631*pow(v,5) - 1497.4521*pow(v,4) + 473.2921*pow(v,3)
+         + 199.07*pow(v,2) - 147.1165*v + 28.1844;
+}
\ No newline at end of file