|
发表于 2013-10-28 13:39:15
|
显示全部楼层
/*
单光感巡线 boylong 2013/10/28/ 13:24
*/
#define WHITE 782 // 白色值
#define BLACK 453 // 黑色值
#define MIDDLE ((WHITE-BLACK)/2+BLACK) // 中间值
#define ERROR 7 // 误差
task main()
{
int tmp = 0;
int test = MIDDLE;
int max = test + ERROR;
int min = test - ERROR;
int ps = 0;
TextOut(25,32,"Ready ...",1);
PlayToneEx(2000,400,100,0);
Wait(1000);
PlayToneEx(2000,400,100,0);
Wait(1000);
PlayToneEx(2000,400,100,0);
Wait(1000);
PlayToneEx(1000,700,100,0);
TextOut(30,32,"GO !",1);
Wait(1000);
SetSensorLight(IN_3,1);
test = MIDDLE;
while(1){
tmp = SensorNormalized(IN_3);
TextOut(2,45,"Te : ");
NumOut(30,45,test);
TextOut(2,35,"Tm : ");
NumOut(30,35,tmp);
TextOut(3,25,"Ps : ");
NumOut(30,25,ps);
if(tmp > max){
ps = (tmp - test) / 2;
if(ps < 10)
ps = 10;
if(ps > 100)
ps = 100;
OnFwd(OUT_C,ps);
}
if(tmp < min){
ps = (test - tmp) / 2;
if(ps < 10)
ps = 10;
if(ps > 100)
ps = 100;
OnFwd(OUT_B,ps);
}
if( (tmp > min) && (tmp < max) ){
OnFwd(OUT_BC,50);
}
}
}
|
|