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.
HCSR04.cpp
00001 #include "HCSR04.h" 00002 #include "mbed.h" 00003 00004 Ultrasonic::Ultrasonic(PinName t, PinName e) : trig(t), echo(e) { 00005 trig=0; 00006 } 00007 00008 int Ultrasonic::echo_duration() { 00009 timer.reset(); 00010 trig = 1; 00011 wait_us(10); 00012 trig = 0; 00013 while(echo == 0); 00014 timer.start(); 00015 while(echo == 1); 00016 timer.stop(); 00017 return timer.read_us(); 00018 } 00019 00020 int Ultrasonic::distance(){ 00021 duration = echo_duration(); 00022 _distance= duration /58 / 2 ; 00023 return _distance; 00024 }
Generated on Wed Aug 24 2022 19:26:27 by
