User manual

36
3.3.3 Type of Call Function
Function of analog-to-digital converter to detect presence of object:
Figure 3.12 : Analog-to-digital call function
Function of analog-to-digital converter to calculate height:
Figure 3.13 : Analog-to-digital call function for sensor 3
void readSensor(void)
{
int j;
for(j = 0 ; j < 10 ; j++) // take analog result for 10 times
{
s1_value = s1_value + ADC_Read(1);
s2_value = s2_value + ADC_Read(2);
}
s1_value = s1_value/10; //get average
s2_value = s2_value/10;
if (s1_value>95)
sensor1=0; //detect object
else
sensor1=1; //no object
if (s2_value>95)
sensor2=0; //detect object
else
sensor2=1; //no object
}
void readSensor3(void)
{
int j;
for(j = 0 ; j < 10 ; j++) // take analog result for 10 times
{
s3_value = s3_value + ADC_Read(3);
}
s3_value = s3_value/10; //get average
}