Permalink
Browse files

Use CM instead of M

  • Loading branch information...
Matt Williamson
Matt Williamson committed Feb 13, 2012
1 parent bd3c1bc commit 9a645787abec34a00e1d42af44d0abda8f4494a1
Showing with 6 additions and 6 deletions.
  1. +5 −5 Sonar/Ultrasound.cpp
  2. +1 −1 Sonar/Ultrasound.h
View
@@ -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
@@ -15,7 +15,7 @@
class Ultrasound {
public:
Ultrasound(int pin);
- float read();
+ int read();
private:
int _pin;
};

0 comments on commit 9a64578

Please sign in to comment.