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.
distance.cpp
00001 // HC-SR04 Device 00002 #include "distance.h" 00003 #include "mbed.h" 00004 00005 Timer pulsetime; 00006 DigitalOut trigger(p21); 00007 InterruptIn echo(p22); 00008 unsigned int pulsedur; 00009 unsigned int distance; 00010 00011 void isr_rise(void) 00012 { 00013 pulsetime.start(); 00014 } 00015 00016 void isr_fall(void) 00017 { 00018 pulsetime.stop(); 00019 pulsedur = pulsetime.read_us(); 00020 distance= (pulsedur*343)/20000; 00021 pulsetime.reset(); 00022 } 00023 00024 unsigned int getDist() //cm 00025 { 00026 // init 00027 pulsetime.stop(); 00028 pulsetime.reset(); 00029 echo.rise(&isr_rise); 00030 echo.fall(&isr_fall); 00031 trigger=0; 00032 00033 // start 00034 trigger=1; 00035 wait_us(10); 00036 trigger=0; 00037 wait_us(10); 00038 00039 return distance; 00040 }
Generated on Sat Jul 30 2022 22:13:18 by
1.7.2