![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ER2
Revision 0:a6e925f144a4, committed 2021-06-02
- Comitter:
- dorian06
- Date:
- Wed Jun 02 07:24:41 2021 +0000
- Commit message:
- capt
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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jun 02 07:24:41 2021 +0000 @@ -0,0 +1,40 @@ +#include "mbed.h" +AnalogOut trig(p16); +InterruptIn Echo(p15); +Timer T1; +Ticker T2; +void Trig(void); +void FM(void); +void FD(void); +float temp; +int main() +{ + T2.attach(&Trig,1); + float dis; + Echo.rise(&FM); + Echo.fall(&FD); + while(1) { + dis =17/(100*temp); + printf("cm=%g\n\r",dis); + + + } +} + +void Trig(void) +{ + trig=1; + wait_us(50); + trig=0; +} +void FM(void) +{ + T1.stop(); + T1.reset(); + T1.start(); +} +void FD(void) +{ + T1.stop(); + temp=T1.read(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jun 02 07:24:41 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file