
xxx_Sonar-HC-SR04_Lsg
Dependencies: HC_SR04_Ultrasonic_Library
main.cpp
- Committer:
- itbusch
- Date:
- 2022-02-23
- Revision:
- 1:ea41d3c33200
- Parent:
- 0:b0a3597dffa9
File content as of revision 1:ea41d3c33200:
#include "mbed.h" #include "ultrasonic.h" void dist(int distance) { //put code here to happen when the distance is changed printf("Distance changed to %dmm\r\n", distance); } ultrasonic mu(D2, D4, 100ms, 1s, &dist); //Set the trigger pin to D2 and the echo pin to D4 //have updates every .1 seconds and a timeout after 1 //second, and call dist when the distance changes int main() { mu.startUpdates();//start mesuring the distance while(1) { //Do something else here mu.checkDistance(); //call checkDistance() as much as possible, as this is where //the class checks if dist needs to be called. } }