ultrasonic sensors for roboticized zuca project

Dependencies:   HC_SR04_Ultrasonic_Library mbed

Fork of Nucleo_UltrasonicHelloWorld by EJ Teb

Committer:
Abraxas3d
Date:
Fri Jul 21 17:46:29 2017 +0000
Revision:
2:1673deaeefad
Parent:
1:4a5586eb1765
Child:
3:d0e45e12a03f
Initial bit of code for ultrasonic detection for Robotized Zuca.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ejteb 0:1704ea055c4f 1 #include "mbed.h"
ejteb 0:1704ea055c4f 2 #include "ultrasonic.h"
ejteb 0:1704ea055c4f 3
Abraxas3d 2:1673deaeefad 4 Serial pc(USBTX, USBRX); // tx, rx
Abraxas3d 2:1673deaeefad 5
ejteb 0:1704ea055c4f 6 void dist(int distance)
ejteb 0:1704ea055c4f 7 {
ejteb 1:4a5586eb1765 8 //put code here to happen when the distance is changed
Abraxas3d 2:1673deaeefad 9 pc.printf("Distance changed to %dmm\r\n", distance);
Abraxas3d 2:1673deaeefad 10 //pc.printf("Distance changed!\n");
Abraxas3d 2:1673deaeefad 11 //printf("Distance changed!\r\n");
ejteb 0:1704ea055c4f 12 }
ejteb 0:1704ea055c4f 13
Abraxas3d 2:1673deaeefad 14 //ultrasonic mu(D8, D9, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9
Abraxas3d 2:1673deaeefad 15 //have updates every .1 seconds and a timeout after 1
Abraxas3d 2:1673deaeefad 16 //second, and call dist when the distance changes
Abraxas3d 2:1673deaeefad 17
Abraxas3d 2:1673deaeefad 18 ultrasonic mu(p30, p29, .1, 1, &dist); //Set the trigger pin to D30 and the echo pin to D29
ejteb 1:4a5586eb1765 19 //have updates every .1 seconds and a timeout after 1
ejteb 1:4a5586eb1765 20 //second, and call dist when the distance changes
ejteb 0:1704ea055c4f 21
ejteb 0:1704ea055c4f 22 int main()
ejteb 0:1704ea055c4f 23 {
Abraxas3d 2:1673deaeefad 24 mu.startUpdates();//start measuring the distance
ejteb 0:1704ea055c4f 25 while(1)
ejteb 0:1704ea055c4f 26 {
ejteb 1:4a5586eb1765 27 //Do something else here
ejteb 1:4a5586eb1765 28 mu.checkDistance(); //call checkDistance() as much as possible, as this is where
ejteb 1:4a5586eb1765 29 //the class checks if dist needs to be called.
ejteb 0:1704ea055c4f 30 }
ejteb 0:1704ea055c4f 31 }