Match Lab
/
sample_HCSR04
demo program for HCSR04.
Conection
main.cpp@0:a982b6866f6c, 2015-03-29 (annotated)
- Committer:
- Match314
- Date:
- Sun Mar 29 09:59:44 2015 +0000
- Revision:
- 0:a982b6866f6c
up
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Match314 | 0:a982b6866f6c | 1 | #include "mbed.h" |
Match314 | 0:a982b6866f6c | 2 | #include "hcsr04.h" |
Match314 | 0:a982b6866f6c | 3 | |
Match314 | 0:a982b6866f6c | 4 | HCSR04 sensor(PB_8, PB_9); |
Match314 | 0:a982b6866f6c | 5 | Serial pc(USBTX, USBRX); |
Match314 | 0:a982b6866f6c | 6 | |
Match314 | 0:a982b6866f6c | 7 | int main() { |
Match314 | 0:a982b6866f6c | 8 | pc.baud(921600); |
Match314 | 0:a982b6866f6c | 9 | |
Match314 | 0:a982b6866f6c | 10 | while(1) { |
Match314 | 0:a982b6866f6c | 11 | sensor.start(); |
Match314 | 0:a982b6866f6c | 12 | wait_ms(100); |
Match314 | 0:a982b6866f6c | 13 | pc.printf("%dcm\n", sensor.get_dist_cm()); |
Match314 | 0:a982b6866f6c | 14 | } |
Match314 | 0:a982b6866f6c | 15 | } |