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.
Revision 0:548da052d6e4, committed 2016-03-24
- Comitter:
- jupark
- Date:
- Thu Mar 24 01:11:51 2016 +0000
- Commit message:
- part2;
Changed in this revision
--- /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