Ultrasound
Dependencies: HC_SR04_Ultrasonic_Library mbed
Fork of Nucleo_UltrasonicHelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "ultrasonic.h" 00003 00004 digitalIn Signal(D12); 00005 digitalIn Trig(); 00006 digitalIn Echo(); 00007 00008 digitalOut Threshold(D13); 00009 digitalOut HVOff(D11); 00010 digitalOut Tx1(D10); 00011 digitalOut Tx2(D9); 00012 00013 void dist(int distance) 00014 { 00015 //put code here to happen when the distance is changed 00016 printf("Distance changed to %dmm\r\n", distance); 00017 } 00018 00019 ultrasonic mu(D8, D9, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9 00020 //have updates every .1 seconds and a timeout after 1 00021 //second, and call dist when the distance changes 00022 00023 int main() 00024 { 00025 mu.startUpdates();//start mesuring the distance 00026 while(1) 00027 { 00028 //Do something else here 00029 mu.checkDistance(); //call checkDistance() as much as possible, as this is where 00030 //the class checks if dist needs to be called. 00031 } 00032 }
Generated on Fri Jul 22 2022 11:51:50 by
1.7.2
