|
这是偶完成的第一个作品,虽然很简单,但是也是一个收获吧!
因为是第一个值得纪念,所以拍了视频,大家不要笑!
代码如下,希望对跟我一样的新手有点帮助
#define COLOR_SENSOR IN_3
#define Black_mark 1 //Define black mark value
/*
black:1,
blue:2
green:3
yellow:4
red:5
white:6
*/
task main()
{
SetSensorColorFull(COLOR_SENSOR); //set the value of color sensor
int raw[3]={0,0,0};
int norm[3]={0,0,0};
int scaled[3]={0,0,0};
int colorval;
OnFwd(OUT_AC, 20);
while (true)
{
ReadSensorColorEx(COLOR_SENSOR, colorval, raw, norm, scaled); // The return value of colorval is the color mark after processed.
NumOut(20, 10, colorval); //Diplay the colorval on the LCD
if (colorval > Black_mark)
{
OnRev(OUT_C, 40);
Wait(100);
until(Sensor(IN_3) <= Black_mark);
OnFwd(OUT_AC, 40);
}
}
} |
评分
-
查看全部评分
|