Create this program

Dependencies:   mbed HCSR04 HMC6352 PID TextLCD

Revision:
2:a8bbf677e774
Parent:
1:d0cada9a5381
Child:
3:901d18b901b4
--- a/ultrasonic.h	Tue Aug 04 04:13:02 2015 +0000
+++ b/ultrasonic.h	Thu Aug 06 00:19:29 2015 +0000
@@ -1,3 +1,10 @@
+/**
+ * @file   : ultrasonic.h (1.0)
+ * @brief  : measure distance from something
+ * @author : Shinnosuke KOIKE
+ * @date   : 2015/08/04
+ */
+
 #ifndef ULTRASONIC_H
 #define ULTRASONIC_H
 
@@ -5,27 +12,29 @@
 #include "hcsr04.h"
 
 class Ultrasonic {
+public:
+    Ultrasonic(PinName trig, PinName echo);
+    int measureDist(void);
+
 private:
     HCSR04* hcsr04;
-
-public:
-    int dist;
-    Ultrasonic(PinName trig, PinName echo);
-    void measureDist(void);
 };
 
+// initialize
 Ultrasonic::Ultrasonic(PinName trig, PinName echo) {
     hcsr04 = new HCSR04(trig, echo);
 }
 
-void Ultrasonic::measureDist(void) {
+// return distance from something
+int Ultrasonic::measureDist(void) {
     wait(0.1);
-    this->dist = hcsr04->distance();
+    int dist = hcsr04->distance();
+    return dist;
 }
 
 #endif
 
-/*
+/**
  * example program
 
 #include "mbed.h"
@@ -34,8 +43,7 @@
 int main(void) {
     Ultrasonic ultrasonic(D12, D13);
     while (1) {
-        ultrasonic.measureDist();
-        pc.printf("%d\r\n", ultrasonic.dist);
+        pc.printf("%d\r\n", ultrasonic.measureDist());
     }
 }
- */
\ No newline at end of file
+ */