![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
lknds
Dependencies: mbed TrapezoidControl Pulse QEI
Diff: Input/Ultrasonic/USS/USS.cpp
- Revision:
- 25:d367d1e7a153
- Parent:
- 24:370616a56815
--- a/Input/Ultrasonic/USS/USS.cpp Wed Sep 18 02:03:56 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -#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_; -} \ No newline at end of file