Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 Serial pc(USBTX,USBRX); 00004 DigitalOut trig(p21); 00005 DigitalOut testled(LED1); 00006 DigitalIn echo(p22); 00007 Timer t; 00008 #define sonic_spead 343.595*100;// cm 00009 00010 int main() { 00011 double time; 00012 while(1) { 00013 testled = 0; 00014 t.reset(); 00015 trig = 1; 00016 time = 0; 00017 wait_us(10); 00018 trig = 0; 00019 if (echo == 1) { 00020 t.start(); 00021 while(1){ 00022 if(echo == 0) { 00023 testled = 1; 00024 t.stop(); 00025 time = t.read(); 00026 time = time / 2.0 *sonic_spead; 00027 pc.printf("%lfcm\n\r",time); 00028 t.reset(); 00029 break; 00030 } 00031 } 00032 } 00033 } 00034 }
Generated on Sun Jul 24 2022 00:10:46 by
1.7.2