Ultrasound
Dependencies: HC_SR04_Ultrasonic_Library mbed
Fork of Nucleo_UltrasonicHelloWorld by
main.cpp@2:1be6e9ba5793, 2015-03-05 (annotated)
- Committer:
- VegardMidt
- Date:
- Thu Mar 05 09:03:51 2015 +0000
- Revision:
- 2:1be6e9ba5793
- Parent:
- 1:4a5586eb1765
Ultrasound;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ejteb | 0:1704ea055c4f | 1 | #include "mbed.h" |
ejteb | 0:1704ea055c4f | 2 | #include "ultrasonic.h" |
ejteb | 0:1704ea055c4f | 3 | |
VegardMidt | 2:1be6e9ba5793 | 4 | digitalIn Signal(D12); |
VegardMidt | 2:1be6e9ba5793 | 5 | digitalIn Trig(); |
VegardMidt | 2:1be6e9ba5793 | 6 | digitalIn Echo(); |
VegardMidt | 2:1be6e9ba5793 | 7 | |
VegardMidt | 2:1be6e9ba5793 | 8 | digitalOut Threshold(D13); |
VegardMidt | 2:1be6e9ba5793 | 9 | digitalOut HVOff(D11); |
VegardMidt | 2:1be6e9ba5793 | 10 | digitalOut Tx1(D10); |
VegardMidt | 2:1be6e9ba5793 | 11 | digitalOut Tx2(D9); |
VegardMidt | 2:1be6e9ba5793 | 12 | |
ejteb | 0:1704ea055c4f | 13 | void dist(int distance) |
ejteb | 0:1704ea055c4f | 14 | { |
ejteb | 1:4a5586eb1765 | 15 | //put code here to happen when the distance is changed |
ejteb | 1:4a5586eb1765 | 16 | printf("Distance changed to %dmm\r\n", distance); |
ejteb | 0:1704ea055c4f | 17 | } |
ejteb | 0:1704ea055c4f | 18 | |
ejteb | 1:4a5586eb1765 | 19 | ultrasonic mu(D8, D9, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9 |
ejteb | 1:4a5586eb1765 | 20 | //have updates every .1 seconds and a timeout after 1 |
ejteb | 1:4a5586eb1765 | 21 | //second, and call dist when the distance changes |
ejteb | 0:1704ea055c4f | 22 | |
ejteb | 0:1704ea055c4f | 23 | int main() |
ejteb | 0:1704ea055c4f | 24 | { |
ejteb | 1:4a5586eb1765 | 25 | mu.startUpdates();//start mesuring the distance |
ejteb | 0:1704ea055c4f | 26 | while(1) |
ejteb | 0:1704ea055c4f | 27 | { |
ejteb | 1:4a5586eb1765 | 28 | //Do something else here |
ejteb | 1:4a5586eb1765 | 29 | mu.checkDistance(); //call checkDistance() as much as possible, as this is where |
ejteb | 1:4a5586eb1765 | 30 | //the class checks if dist needs to be called. |
ejteb | 0:1704ea055c4f | 31 | } |
ejteb | 0:1704ea055c4f | 32 | } |