Justin Park / Mbed 2 deprecated Lab8Part1

Dependencies:   C12832_lcd mbed

Revision:
0:9d14f8ea9b2c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 24 01:11:01 2016 +0000
@@ -0,0 +1,38 @@
+/**********************************************
+MIDN Justin Park and Drew Moore
+10 March 2016
+SY202 Lab 8 Part 1
+Description: This function calibrates the distance
+                measured by an Ultrasonic sensor
+
+*********************************************/
+#include "mbed.h"
+#include "C12832_lcd.h"
+
+//Initialize the LCD display
+C12832_LCD lcd;
+
+//Read AnalogIn from pin 17
+AnalogIn sensor(p17); // Declare a sensor object with analog input
+
+//Initialize float variables
+float sensorData; // Variable to store the raw output from the sensor
+float distance; // Variable to store the actual distance measured by
+                // the sensor after calibration.
+
+int main() {
+    while(1) {
+        //Put data from the sensor into a variable
+        sensorData = sensor.read();
+        // Turn voltage value into distance using equation from excel sheet
+         
+        distance = 399.86 * sensorData - 0.6574; // Use this formula for a 4.7V source.
+        //Use: distance = 551.68 * sensorData + 0.1376; for a 3.3V source
+        
+        //print distance on the LCD in the middle row      
+        lcd.locate(0,10);
+        //lcd.printf("%f", sensorData);
+        lcd.printf("%f", distance);
+        wait(1); // Pause the program every second for readability
+    }
+}