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 00005 HCSR04::HCSR04(PinName trigger, PinName echo) : _t(trigger), _e(echo) { 00006 wait(0.1); 00007 } 00008 00009 float HCSR04::getCm(void){ 00010 distcm = readEcho()/58; 00011 return distcm; 00012 } 00013 00014 float HCSR04::getIn(void){ 00015 distin = readEcho()/148; 00016 return distin; 00017 } 00018 00019 float HCSR04::readEcho(void){ 00020 _t=1; //Inicio do trigger 00021 wait_us(10); //10us de pulso 00022 _t=0; //Fim do trigger 00023 while(!_e); 00024 _tempo.start(); 00025 while(_e); 00026 tdist = _tempo.read_us(); //Leitura do tempo transcorrido 00027 _tempo.stop(); //Paro o temporizador 00028 _tempo.reset(); //Reset para o próximo ciclo 00029 return tdist; 00030 }
Generated on Sun Aug 7 2022 14:02:38 by
1.7.2