HOme Sheriff And Lamp
Dependencies: CameraC328 HCSR04 SDFileSystem WIZnetInterface mbed
Fork of HoSAL by
Diff: rev_Hcsr04.cpp
- Revision:
- 0:35211a622a44
- Child:
- 2:3c7526a1893a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rev_Hcsr04.cpp Tue Aug 11 16:05:02 2015 +0000
@@ -0,0 +1,58 @@
+/*
+# coded by revival / uasonice (at) gmail.com
+# DATE: 2015/08/10 / Mon Aug 10 21:21:36 KST 2015
+#
+# DESCRIPTION:
+# copied from Ultrasonic by Ryu
+#
+*/
+
+#include "mbed.h"
+#include <stdio.h>
+#include <string.h>
+
+#define DEBUG_TYPE 1
+#define P_ uart.printf
+#include "rev_config.h"
+
+#include "rev_Hcsr04.h"
+
+//HCSR04 sensor(D12, D11);
+extern HCSR04 sensor;
+
+int sum_dist[3];
+int avg_dist = 0;
+int index_dist = 0;
+long distance_cm = 0; //ryuhs74@20150810 - Add
+
+#if defined(USE_MEASURE_DISTANCE)
+int get_distance(void)
+{
+
+ while (true) {
+ distance_cm = sensor.distance(); //ryuhs74@20150810 - cm 단위 측정 거리 return
+ if( index_dist < 3){ //ryuhs74@20150810
+ sum_dist[index_dist] = distance_cm;
+ DM_fLN("sum_dist[%d] = %d", index_dist, sum_dist[index_dist]);
+ index_dist ++;
+ } else {
+ avg_dist = 0;
+ index_dist = 0;
+
+ for(int i =0; i<3;i++){
+ avg_dist += sum_dist[i];
+ }
+
+ avg_dist /= 3;
+ return avg_dist;
+ }
+#if 0
+ wait_ms(10);
+#else
+ break;
+#endif
+ }
+ return 8192;
+}
+#endif // defined(USE_MEASURE_DISTANCE)
+
