4180Lab3Part1
Dependencies: HC_SR04_Ultrasonic_Library mbed
Fork of LPC1768_HCSR04_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "ultrasonic.h" 00003 00004 void dist(int distance) 00005 { 00006 //put code here to execute when the distance has changed 00007 if(distance*0.00328084 < 40) { 00008 printf("Distance %f ft\r\n", distance*0.00328084); 00009 } 00010 } 00011 00012 ultrasonic mu(p6, p7, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9 00013 //have updates every .1 seconds and a timeout after 1 00014 //second, and call dist when the distance changes 00015 00016 int main() 00017 { 00018 mu.startUpdates();//start measuring the distance 00019 while(1) 00020 { 00021 //Do something else here 00022 mu.checkDistance(); //call checkDistance() as much as possible, as this is where 00023 //the class checks if dist needs to be called. 00024 } 00025 }
Generated on Fri Jul 15 2022 17:19:31 by 1.7.2