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
- Committer:
- marvas
- Date:
- 2018-12-09
- Revision:
- 0:530d4c35d92a
File content as of revision 0:530d4c35d92a:
#include "hcsr04.h"
#include "mbed.h"
/*
HCSR04 Ultrasonik sensör kullanýmý
Mehmet Akif Arvas
Herkese açýktýr. Telif hakký yoktur. :))
*/
HCSR04::HCSR04(PinName t, PinName e) : trig(t), echo(e) {}
int HCSR04::echo_sure() {
timer.reset(); //reset timer
trig=0; // trigger low
wait_us(2); // wait
trig=1; // trigger high
wait_us(10);
trig=0; // trigger low
while(!echo); // start pulseIN
timer.start();
while(echo);
timer.stop();
return timer.read_us();
}
//return distance in cm
int HCSR04::uzaklik(){
sure = echo_sure();
mesafe_cm = (sure/2)/29.1 ;
return mesafe_cm;
}