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