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
main.cpp
00001 #include "mbed.h" 00002 #include "ultrasonic.h" 00003 00004 void dist(int distance) 00005 { 00006 //put code here to happen when the distance is changed 00007 printf("Distance changed to %dmm\r\n", distance); 00008 } 00009 00010 ultrasonic mu(D8, D9, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9 00011 //have updates every .1 seconds and a timeout after 1 00012 //second, and call dist when the distance changes 00013 00014 int main() 00015 { 00016 mu.startUpdates();//start mesuring the distance 00017 while(1) 00018 { 00019 //Do something else here 00020 mu.checkDistance(); //call checkDistance() as much as possible, as this is where 00021 //the class checks if dist needs to be called. 00022 } 00023 }
Generated on Wed Jul 13 2022 13:36:46 by
1.7.2
HC-SR04