I need some help regarding the changes of codes.
What am I going to change is the Ultrasonic part. The web given codes as follow:
- CODE: SELECT_ALL_CODE
while(1)
{
lcd_goto(20);
distance = us_value(n);
dis_num(distance);
if (distance> 40)
{
forward();
SPEEDL = 255;
SPEEDR = 255;
buzzer = 0;
}
else if (distance> 30)
{
forward();
SPEEDL = 230;
SPEEDR = 230;
buzzer = 0;
}
else if( distance >20)
{
stop();
buzzer = 0;
}
Now my problem is, I would like to change the range of the distance. When I change either one of it, there will show this to me:
********** Build failed! **********
So, what should I do nw?
Is it affected by the "us_value(n)"?
Sadly, I don't understand the formula given by "us_value(n)" as below :
- CODE: SELECT_ALL_CODE
//====================================================================================================
unsigned int us_value (unsigned char mode)
{
unsigned int value;
switch (mode)
{
case 1: read_adc(CHANNEL0);
value = result; // max vslue 2.55v = 2.55/5 *1024 - 1 = 522, resolution = 10mV/ inch, 10m/5*1024 =~ 2
break;
case 2: value = TH; // each value = 256*4/20mhz = 51.2us, i inch = 147us
break; // can change using smaller timer prescale, but resulation fixed 147us / inch
case 3: if ( data [0]=='R') value = (data[1] - 0x30)*100+ (data[2] - 0x30)*10+ (data[3] - 0x30); // 1 = 1 inch
else
{
lcd_goto(20); // if stater byte is not 'R', Display 'not connected'
send_string("not connected");
while(1); // loop forever
}
default: ;
}
return value;
//====================================================================================================