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.
Input/Ultrasonic/USS/USS.cpp
- Committer:
- M_souta
- Date:
- 2019-09-17
- Revision:
- 22:7d93f79a3686
File content as of revision 22:7d93f79a3686:
#include "USS.h"
#include "mbed.h"
USS::USS(PinName echoPin, PinName trigPin, PinName tempPin)
:echo_(echoPin), trig_(trigPin), temp_(tempPin)
{
distance_ = 0;
}
double USS::ReadDis(void) {
int temp = temp_.getTemperature();
double duration = echo_.read_high_us(5000);
trig_.write_us(1,10);
if(duration > 0){
duration /= 2;
double sspead = 331.5+0.6*temp;
distance_ = duration*sspead*100/1000000;
} else distance_ = 0;
return distance_;
}
double USS::GetDis(void) {
return distance_;
}