T Nara
/
Echo
Ultrasonic sensor used HC-SR04
Revision 0:6947b0547f9f, committed 2015-01-18
- Comitter:
- tknara
- Date:
- Sun Jan 18 13:42:41 2015 +0000
- Commit message:
- Ultrasonic sensor
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 6947b0547f9f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Jan 18 13:42:41 2015 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" + +Serial pc(USBTX,USBRX); +DigitalOut trig(p21); +DigitalOut testled(LED1); +DigitalIn echo(p22); +Timer t; +#define sonic_spead 343.595*100;// cm + +int main() { + double time; + while(1) { + testled = 0; + t.reset(); + trig = 1; + time = 0; + wait_us(10); + trig = 0; + if (echo == 1) { + t.start(); + while(1){ + if(echo == 0) { + testled = 1; + t.stop(); + time = t.read(); + time = time / 2.0 *sonic_spead; + pc.printf("%lfcm\n\r",time); + t.reset(); + break; + } + } + } + } +}
diff -r 000000000000 -r 6947b0547f9f mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Jan 18 13:42:41 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file