找回密码
 马上注册

QQ登录

只需一步,快速开始

查看: 4462|回复: 0

NXC颜色传感器程序 求解析

[复制链接]
发表于 2012-8-10 16:33:13 | 显示全部楼层 |阅读模式
悬赏5乐币未解决
麻烦哪位在程序旁边注释一下没一行程序的意思!谢谢

#define COLOR_SENSOR S2

#define COLOR_MOVE OUT_C
#define COLOR_DROP OUT_B
task main()
{

SetSensorTouch(TOUCH_SENSOR_DROP);
SetSensorColorFull(COLOR_SENSOR);

OnFwd(COLOR_MOVE,50);//马达旋转

Off(COLOR_MOVE);
RotateMotorEx(COLOR_MOVE,50,55,0,false,true);//转动50度

while(true)
{
int degrees = 0;
unsigned int raw[];
int colorval,scaled;
unsigned int norm[];

ReadSensorColorEx(COLOR_SENSOR, colorval, raw, norm, scaled);//colorval可以返回程序detect到6种颜色,raw可以返回RGB的值

switch (colorval)
{
case INPUT_REDCOLOR:
degrees = 0;
break;
case INPUT_YELLOWCOLOR:
degrees = 90;
break;
case INPUT_GREENCOLOR:
degrees = 180;
break;
case INPUT_BLUECOLOR:
degrees = 270;
break;
default:
break;
}

RotateMotorEx(COLOR_MOVE,50,degrees,0,false,true);
OnFwd(COLOR_DROP,50);

RotateMotorEx(COLOR_DROP,50,360*0.8,0,false,true);
RotateMotorEx(COLOR_MOVE,50,(360-degrees)%360,0,false,true);
Wait(300);//Delay 300毫秒
}
}

如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

手机版|中文乐高 ( 桂ICP备13001575号-7 )

GMT+8, 2024-11-24 06:08 , Processed in 0.115707 second(s), 18 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表