bool is_school_zone_detected() {
	
	char buf[10];
	bool ret_val = false;
	
	DisableExternalInterrupts();
	
	int a1 = A2D_GetSingleCh_10bit(PIN_IR_SENSOR_1_ADC);
	
	int a3 = A2D_GetSingleCh_10bit(PIN_IR_SENSOR_3_ADC);
	
	int a5 = A2D_GetSingleCh_10bit(PIN_IR_SENSOR_5_ADC);
	
	if(a1 < ADC_BLACK_REFERENCE) {
		
		if(a5 < ADC_BLACK_REFERENCE) {
			
			if(a3 < ADC_BLACK_REFERENCE) {
				ret_val = true;
			}
		}
	}
	
	EnableExternalInterrupts();
	
	return ret_val;
}
Exemple #2
0
 int getDistance(int channel){
 	static const int adcCh[2] ={2,3};
 	static int distanceValue[2][9]={{255,255,255,255,255,255,255,255,255}
 									,{255,255,255,255,255,255,255,255,255}
 	};
 	
 	int tempData[9];
 	volatile int i,adcValue,distance;	
 	
 	adcValue = (int)A2D_GetSingleCh_10bit((unsigned long)adcCh[channel]);  
 	adcValue = (int)adcToDistance(adcValue);	//new distance
 	
 	//shift
 	for(i=8;i>0;i--)
 		distanceValue[channel][i] = distanceValue[channel][i-1];
 		
 	distanceValue[channel][0] = adcValue;	

 	for(i=0;i<9;i++)
 		tempData[i] = distanceValue[channel][i];
 	//median filter
 	distance = medianFilter(tempData,9,5);
 	
 	return distance;
 }