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.
Dependencies: HC_SR04_Ultrasonic_Library mbed
Fork of LPC1768_HCSR04_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "ultrasonic.h" 00003 00004 00005 Serial pc(USBTX, USBRX); 00006 void dist(int distance) 00007 { 00008 //put code here to execute when the distance has changed 00009 float feet_distance = distance * 0.00328084f; 00010 pc.printf("Distance %d mm\rt\n", distance); 00011 pc.printf("Distance %.5f ft\r\n", feet_distance); 00012 } 00013 00014 ultrasonic mu(p6, p7, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9 00015 //have updates every .1 seconds and a timeout after 1 00016 //second, and call dist when the distance changes 00017 00018 int main() 00019 { 00020 mu.startUpdates();//start measuring the distance 00021 while(1) 00022 { 00023 //Do something else here 00024 mu.checkDistance(); //call checkDistance() as much as possible, as this is where 00025 //the class checks if dist needs to be called. 00026 } 00027 }
Generated on Tue Jul 19 2022 01:53:30 by
1.7.2
