HOme Sheriff And Lamp
Dependencies: CameraC328 HCSR04 SDFileSystem WIZnetInterface mbed
Fork of HoSAL by
rev_Hcsr04.cpp
- Committer:
- uasonice
- Date:
- 2015-08-11
- Revision:
- 2:3c7526a1893a
- Parent:
- 0:35211a622a44
- Child:
- 8:28f7b30c1ae4
File content as of revision 2:3c7526a1893a:
/*
# 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"
#if defined(USE_MEASURE_DISTANCE)
long avg_dist = 0;
long distance_cm = 0; //ryuhs74@20150810 - Add
uint8_t index_dist = 0;
long sum_dist[3];
int get_distance(HCSR04 *pH)
{
while (true) {
distance_cm = pH->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;
DM_fLN("avg: %d", avg_dist);
return avg_dist;
}
#if 0
wait_ms(10);
#else
break;
#endif
}
return 8192;
}
#endif // defined(USE_MEASURE_DISTANCE)
