|
发表于 2015-1-13 11:50:41
|
显示全部楼层
File菜单下可以open sample Program,打开Sample Programs\EV3,里面有很多示例程序。其中Basic_Colour_Detection.c内容如下:
- #pragma config(Sensor, S3, Colour, sensorEV3_Color, modeEV3Color_Color)
- //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
- /*
- Colour sensor modes
- 0 - modeEV3Color_Reflected
- 1 - modeEV3Color_Ambient
- 2 - modeEV3Color_Color
- 3 - modeEV3Color_Reflected_Raw
- 4 - modeEV3Color_RGB_Raw
- 5 - modeEV3Color_Calibration - Not utilized
- */
- task main()
- {
- short currentColour;
- while (true)
- {
- // Colours range from 0 to 7
- // None = 0
- // Black = 1
- // Blue = 2
- // Green = 3
- // Yellow = 4
- // Red = 5
- // White = 6
- // Brown = 7
- currentColour = SensorValue[Colour];
- switch(currentColour)
- {
- case 0: displayCenteredBigTextLine(4, "none"); break;
- case 1: displayCenteredBigTextLine(4, "black"); break;
- case 2: displayCenteredBigTextLine(4, "blue"); break;
- case 3: displayCenteredBigTextLine(4, "green"); break;
- case 4: displayCenteredBigTextLine(4, "yellow"); break;
- case 5: displayCenteredBigTextLine(4, "red"); break;
- case 6: displayCenteredBigTextLine(4, "white"); break;
- case 7: displayCenteredBigTextLine(4, "brown"); break;
- default: displayCenteredBigTextLine(4, "unknown");
- }
- // Wait 20 ms to get 50 readings per second
- sleep(20);
- }
- }
复制代码
|
|