RYU HoSeong

Dependencies:   HC_SR04_Ultrasonic_Library mbed-rtos mbed-src mbed HCSR04

Fork of Nucleo_UltrasonicHelloWorld by EJ Teb

Revision:
4:eb5a51640b43
Parent:
2:3dcb6f86ed22
Child:
5:e1849ee9651d
--- a/main.cpp	Thu Aug 06 12:28:55 2015 +0000
+++ b/main.cpp	Fri Aug 07 00:12:47 2015 +0000
@@ -1,5 +1,11 @@
 #include "mbed.h"
+
+//#define TEST_ULTRASONIC
+#ifdef TEST_ULTRASONIC   
 #include "ultrasonic.h"
+#else
+#include "hcsr04.h"
+#endif
 
 
 //#define USE_THREAD
@@ -45,11 +51,13 @@
     pc.printf("Distance changed to %d mm\r\n", distance);
 }
 
-#define TEST_ULTRASONIC
+
 #ifdef TEST_ULTRASONIC
 ultrasonic mu(D8, D9, .1, 1, &dist);    //Set the trigger pin to D8 and the echo pin to D9
 //have updates every .1 seconds and a timeout after 1
 //second, and call dist when the distance changes
+#else
+HCSR04 sensor(D12, D11); 
 #endif
 
 int main()
@@ -61,17 +69,25 @@
 #endif
 
     while(1) {
-#ifdef TEST_ULTRASONIC
+
         pc.printf("Before mu.checkDistance();\n");
         //Do something else here
+#ifdef TEST_ULTRASONIC
         mu.checkDistance();     //call checkDistance() as much as possible, as this is where
+#else
+        long distance = sensor.distance(); 
+#endif
         //the class checks if dist needs to be called.
         pc.printf("After mu.checkDistance();\n");
                
        //ryuhs74@20150712 START - 
         if( index_dist < 3){
             pc.printf("Before mu.getCurrentDistance();\n");
+#ifdef TEST_ULTRASONIC
             sum_dist[index_dist] = mu.getCurrentDistance();
+#else
+            sum_dist[index_dist] = distance;
+#endif
             pc.printf("sum_dist[index_dist(%d)] = %d\n", index_dist, sum_dist[index_dist]);
             index_dist ++;
         } else {
@@ -98,9 +114,8 @@
                 
             }
         }
-#endif
         pc.printf("wait(1)\n");
         //ryuhs74@20150712 - END        
-        wait(1); //ryuhs7474@20150713 - 초당 한번씩 딜레이를 준다          
+        wait(1.0); //ryuhs7474@20150713 - 초당 한번씩 딜레이를 준다          
     }
 }