stephen smitherman
/
UltraTest
HCSR04
main.cpp@0:f91b4b2acbe1, 2014-03-11 (annotated)
- Committer:
- srsmitherman
- Date:
- Tue Mar 11 21:20:40 2014 +0000
- Revision:
- 0:f91b4b2acbe1
Test Program for HCSR04
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
srsmitherman | 0:f91b4b2acbe1 | 1 | #include "mbed.h" |
srsmitherman | 0:f91b4b2acbe1 | 2 | #include "HCSR04.h" |
srsmitherman | 0:f91b4b2acbe1 | 3 | |
srsmitherman | 0:f91b4b2acbe1 | 4 | DigitalOut myled(LED1); |
srsmitherman | 0:f91b4b2acbe1 | 5 | Serial pc(USBTX,USBRX); |
srsmitherman | 0:f91b4b2acbe1 | 6 | HCSR04 ultra(p12,p11); |
srsmitherman | 0:f91b4b2acbe1 | 7 | |
srsmitherman | 0:f91b4b2acbe1 | 8 | float range=0; |
srsmitherman | 0:f91b4b2acbe1 | 9 | |
srsmitherman | 0:f91b4b2acbe1 | 10 | int main() { |
srsmitherman | 0:f91b4b2acbe1 | 11 | |
srsmitherman | 0:f91b4b2acbe1 | 12 | |
srsmitherman | 0:f91b4b2acbe1 | 13 | pc.printf("Program Start\n"); |
srsmitherman | 0:f91b4b2acbe1 | 14 | while(1) { |
srsmitherman | 0:f91b4b2acbe1 | 15 | |
srsmitherman | 0:f91b4b2acbe1 | 16 | ultra.startMeas(); |
srsmitherman | 0:f91b4b2acbe1 | 17 | |
srsmitherman | 0:f91b4b2acbe1 | 18 | wait(0.2); |
srsmitherman | 0:f91b4b2acbe1 | 19 | |
srsmitherman | 0:f91b4b2acbe1 | 20 | |
srsmitherman | 0:f91b4b2acbe1 | 21 | if( ultra.getMeas(range) == RANGE_MEAS_VALID) |
srsmitherman | 0:f91b4b2acbe1 | 22 | { |
srsmitherman | 0:f91b4b2acbe1 | 23 | pc.printf("Range - %f\n\r", range); |
srsmitherman | 0:f91b4b2acbe1 | 24 | } |
srsmitherman | 0:f91b4b2acbe1 | 25 | } |
srsmitherman | 0:f91b4b2acbe1 | 26 | } |