Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use CM instead of M

  • Loading branch information...
commit 9a645787abec34a00e1d42af44d0abda8f4494a1 1 parent bd3c1bc
Matt Williamson authored
Showing with 6 additions and 6 deletions.
  1. +5 −5 Sonar/Ultrasound.cpp
  2. +1 −1  Sonar/Ultrasound.h
View
10 Sonar/Ultrasound.cpp
@@ -11,7 +11,7 @@ Ultrasound::Ultrasound(int pin)
_pin = pin;
}
-float Ultrasound::read()
+int Ultrasound::read()
{
// Send Read Impulse
pinMode(_pin, OUTPUT);
@@ -26,11 +26,11 @@ float Ultrasound::read()
long microseconds = pulseIn(_pin, HIGH, 20000);
// Only half the distance is receiving
+ // half is transmitting
microseconds /= 2;
- float cm = microseconds / SPEED_OF_SOUND;
+ float meters = microseconds / SPEED_OF_SOUND / 100.0;
- // Minimum distance is 3cm
- // cm = cm == 0 ? 3 : cm;
+ meters = meters == 0 ? 3 : meters;
- return cm;
+ return meters * 100;
}
View
2  Sonar/Ultrasound.h
@@ -15,7 +15,7 @@
class Ultrasound {
public:
Ultrasound(int pin);
- float read();
+ int read();
private:
int _pin;
};
Please sign in to comment.
Something went wrong with that request. Please try again.