Justin Park / Mbed 2 deprecated Lab8Part2

Dependencies:   C12832_lcd mbed

Files at this revision

API Documentation at this revision

Comitter:
jupark
Date:
Thu Mar 24 01:11:51 2016 +0000
Commit message:
part2;

Changed in this revision

C12832_lcd.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Thu Mar 24 01:11:51 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 24 01:11:51 2016 +0000
@@ -0,0 +1,53 @@
+/**********************************************
+MIDN Justin Park and Drew Moore
+10 March 2016
+SY202 Lab 8 Part 2
+Description: This function calculates the time
+                a single pulse takes and converts
+                the time into distance in an 
+                Ultrasonic sensor.
+*********************************************/
+#include "mbed.h"
+#include "C12832_lcd.h"
+
+//Initialize the LCD display
+C12832_LCD lcd;
+
+InterruptIn pw_event(p21); // Declare a pulse width object
+Timer t; // Declare a timer object
+
+//Initialize float variables
+float distance; // Variable to store distance from the sensor
+float us = 0; // Variable to store microseconds
+
+// Function to store the time measured from the timer
+void getPw(){
+   us = t.read_us();
+    }
+
+// Function to reset and start the timer
+void rise_int(){
+    t.reset();
+    t.start();
+    }
+
+int main() {
+    while(1) {
+        
+        // Obtain the microseconds it takes for the pulse
+        // to achieve its rise and fall time
+        pw_event.rise(&rise_int);
+        pw_event.fall(&getPw);
+        
+        // Formula based on calibration calculated from the 
+        // excel spreadsheet
+        distance = 0.0066 * us + 0.9024;
+        
+        // Print distance to the LCD display
+        lcd.locate(0,0);
+        lcd.printf("%f", distance);
+        
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Mar 24 01:11:51 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb
\ No newline at end of file