4180Lab3Part1
Dependencies: HC_SR04_Ultrasonic_Library mbed
Fork of LPC1768_HCSR04_HelloWorld by
main.cpp@3:9285821440d2, 2017-02-27 (annotated)
- Committer:
- CRaslawski
- Date:
- Mon Feb 27 22:55:09 2017 +0000
- Revision:
- 3:9285821440d2
- Parent:
- 2:3566c2d1e86b
initial commit
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 | |
ejteb | 0:1704ea055c4f | 4 | void dist(int distance) |
ejteb | 0:1704ea055c4f | 5 | { |
4180_1 | 2:3566c2d1e86b | 6 | //put code here to execute when the distance has changed |
CRaslawski | 3:9285821440d2 | 7 | if(distance*0.00328084 < 40) { |
CRaslawski | 3:9285821440d2 | 8 | printf("Distance %f ft\r\n", distance*0.00328084); |
CRaslawski | 3:9285821440d2 | 9 | } |
ejteb | 0:1704ea055c4f | 10 | } |
ejteb | 0:1704ea055c4f | 11 | |
4180_1 | 2:3566c2d1e86b | 12 | ultrasonic mu(p6, p7, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9 |
ejteb | 1:4a5586eb1765 | 13 | //have updates every .1 seconds and a timeout after 1 |
ejteb | 1:4a5586eb1765 | 14 | //second, and call dist when the distance changes |
ejteb | 0:1704ea055c4f | 15 | |
ejteb | 0:1704ea055c4f | 16 | int main() |
ejteb | 0:1704ea055c4f | 17 | { |
4180_1 | 2:3566c2d1e86b | 18 | mu.startUpdates();//start measuring the distance |
ejteb | 0:1704ea055c4f | 19 | while(1) |
ejteb | 0:1704ea055c4f | 20 | { |
ejteb | 1:4a5586eb1765 | 21 | //Do something else here |
ejteb | 1:4a5586eb1765 | 22 | mu.checkDistance(); //call checkDistance() as much as possible, as this is where |
ejteb | 1:4a5586eb1765 | 23 | //the class checks if dist needs to be called. |
ejteb | 0:1704ea055c4f | 24 | } |
ejteb | 0:1704ea055c4f | 25 | } |