RYU HoSeong
Dependencies: HC_SR04_Ultrasonic_Library mbed-rtos mbed-src mbed HCSR04
Fork of Nucleo_UltrasonicHelloWorld by
Revision 4:eb5a51640b43, committed 2015-08-07
- Comitter:
- ryuhs74
- Date:
- Fri Aug 07 00:12:47 2015 +0000
- Parent:
- 3:b9d991388a77
- Child:
- 5:e1849ee9651d
- Commit message:
- change HC-SRO4 Header file
Changed in this revision
| HCSR04.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HCSR04.lib Fri Aug 07 00:12:47 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/antoniolinux/code/HCSR04/#86b2086be101
--- 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 - 초당 한번씩 딜레이를 준다
}
}
