y = adc_read(0) ;
// ADCON0=0b00000011;
x= ((y*1000*2.5)/9.8);\\convert to distance
ADCON0=0b00000001;
if (1<=x && x<30){
Sound_Init(&PORTB, 0);
//PORTB=0b00000001;
// PORTB.f0=1;
// PORTB.f1=0;
// PORTB.f2=0;
// delay_us(500);
//ADCON0=0b00000001;
}
else if(30<=x && x<80){
Sound_Init(&PORTB, 1);
Tone1();
//PORTB=0b00000010;
// PORTB.f0=0;
// PORTB.f1=1;
// PORTB.f2=0;
//delay_us(500);
// ADCON0=0b00000001;*/
}
else if(80<=x &&x<=120){
Sound_Init(&PORTB, 2);
Tone2();
//PORTB=0b00000100;
// PORTB.f0=1;
// PORTB.f1=0;
// PORTB.f2=1;
// delay_us(500);
//ADCON0=0b00000100;
}
else {
Sound_Init(&PORTB, 3);
Tone3();
//PORTB.f0=1;
// PORTB.f1=1;
//PORTB.f2=1;
// delay_us(500);
//ADCON0=0b00000001;
}
}}
i used LV-MAXSONAR-EZ1 sensor and the if statment didint work in correct way and i want to convert the analog input to cm distance then test if statment i use pic18f2553 with 20Mhz
thx for your rep but the real problem is in the x=(y*1000*2.5)/(9.8);its take time bigger than the ADC reading because this i have always take the faild result
????idont know how to resolve this problem
the sensor give me 9.8 mV for evrey 1 inch,and when i use a tone this problem apear again. can you help me plz to solve his problem?!!!