|
发表于 2013-10-24 12:50:19
|
显示全部楼层
把程序做成颜色比对的方式,不要使用固定的光值
void good(void)
{
int k = 1;
int m = 1;
while(k){
numb_1 = Sensor(IN_3);
if(numb_1 < Null){
TextOut(8,32,"NULL 1");
}
else {
k = 0;
TextOut(8,32,"Detect..1") ;
}
}
fangzhi(1);
PlayToneEx(3000,500,100,0);
k = 1;
m = 1;
while(k){
numb_2 = Sensor(IN_3);
while(m){
if(numb_2 < Null){
TextOut(8,32,"NULL 2");
}
else
m = 0;
}
if((numb_2 > numb_1 - 2) && (numb_2 < numb_1 + 2))
{
PlayToneEx(3000,500,100,0);
fangzhi(1);
TextOut(8,32,"Detect..2") ;
;
}
else{
PlayToneEx(3000,500,100,0);
numb_2 = Sensor(IN_3);
fangzhi(2);
k = 0;
}
}
k = 1;
m = 1;
while(k){
numb_3 = Sensor(IN_3);
while(m){
if(numb_3 < Null){
TextOut(8,32,"NULL 3");
}
else
m = 0;
}
if((numb_3 > numb_1 - 2) && (numb_3 < numb_1 + 2))
{
PlayToneEx(3000,500,100,0);
TextOut(8,32,"Detect..3") ;
fangzhi(1);
}
else{
if((numb_3 > numb_2 - 2) && (numb_3 < numb_2 + 2))
{
PlayToneEx(3000,500,100,0);
TextOut(8,32,"Detect..3") ;
fangzhi(2);
}
else{
PlayToneEx(3000,500,100,0);
numb_3 = Sensor(IN_3);
fangzhi(3);
k = 0;
}
}
}
}
这段代码可以自动比对三种颜色,不用管是什么颜色,只要是不同的就可以区分出来,你有什么写的代码啊
|
|