![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ER2
main.cpp
- Committer:
- dorian06
- Date:
- 2021-06-02
- Revision:
- 0:a6e925f144a4
File content as of revision 0:a6e925f144a4:
#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(); }