ultrasonic sensors for roboticized zuca project
Dependencies: HC_SR04_Ultrasonic_Library mbed
Fork of Nucleo_UltrasonicHelloWorld by
main.cpp
- Committer:
- Abraxas3d
- Date:
- 2017-07-21
- Revision:
- 2:1673deaeefad
- Parent:
- 1:4a5586eb1765
- Child:
- 3:d0e45e12a03f
File content as of revision 2:1673deaeefad:
#include "mbed.h" #include "ultrasonic.h" Serial pc(USBTX, USBRX); // tx, rx void dist(int distance) { //put code here to happen when the distance is changed pc.printf("Distance changed to %dmm\r\n", distance); //pc.printf("Distance changed!\n"); //printf("Distance changed!\r\n"); } //ultrasonic mu(D8, D9, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9 //have updates every .1 seconds and a timeout after 1 //second, and call dist when the distance changes ultrasonic mu(p30, p29, .1, 1, &dist); //Set the trigger pin to D30 and the echo pin to D29 //have updates every .1 seconds and a timeout after 1 //second, and call dist when the distance changes int main() { mu.startUpdates();//start measuring 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. } }