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.
Fork of HCSR04 by
Revision 1:62f97e90a58c, committed 2017-11-18
- Comitter:
- feupos
- Date:
- Sat Nov 18 18:27:18 2017 +0000
- Parent:
- 0:0bda99bb39a4
- Commit message:
- set to float
Changed in this revision
| HCSR04.cpp | Show annotated file Show diff for this revision Revisions of this file |
| HCSR04.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/HCSR04.cpp Tue Oct 18 14:32:12 2011 +0000
+++ b/HCSR04.cpp Sat Nov 18 18:27:18 2017 +0000
@@ -10,7 +10,7 @@
//
//return echo duration in us (refer to digram above)
-long HCSR04::echo_duration() {
+float HCSR04::echo_duration() {
timer.reset();
trig = 0;
wait_us(2);
@@ -27,7 +27,7 @@
//return distance to nearest obstacle or returns -1
//if no obstacle within range
//set sys to cm or inch accordingly
-long HCSR04::distance(int sys){
+float HCSR04::distance(int sys){
duration = echo_duration();
if(duration > 30000)
return -1;
--- a/HCSR04.h Tue Oct 18 14:32:12 2011 +0000
+++ b/HCSR04.h Sat Nov 18 18:27:18 2017 +0000
@@ -26,14 +26,14 @@
class HCSR04 {
public:
HCSR04(PinName t, PinName e);
- long echo_duration();
- long distance(int sys);
+ float echo_duration();
+ float distance(int sys);
private:
DigitalOut trig;
DigitalIn echo;
Timer timer;
- long duration,distacne_cm,distance_inc;
+ float duration,distacne_cm,distance_inc;
};
#endif
\ No newline at end of file
