本帖最后由 千片的↘心↙ 于 2013-8-5 09:07 编辑
光电传感器的配置我就不用讲了吧~~~~ 示例:#pragma config(Sensor,S3, lightSensor, sensorLightActive) 上面这个配置前两节课讲得很清楚了,我们讲点其他的语法之类的 - #pragma config(Sensor, S3, lightSensor, sensorLightActive)
- task main()
- {
- wait1Msec(50);
- while(true)
- {
- if(SensorValue[lightSensor]< 45)
- {
- motor[motorB]= 60;
- motor[motorC]= 20;
- }
- else
- {
- motor[motorB]= 20;
- motor[motorC]= 60;
- }
- }
- }
复制代码 上面有一段程序,有一个语法点 if ···else··· 意思是:如果···其他··· 如果满足if后的括号里为真那么就执行if下面大括号的程序否则if后面的小括号是假,那么执行else后面的大括号的程序 还有就是注意一下程序一开始的等待语句,上节课讲过是使程序稳定下来,稳定光感的读值 - #pragma config(Sensor, S3, lightSensor, sensorLightActive)
- task main()
- {
- wait1Msec(100)
- while(SensorValue(lightSensor)>45)
- {
- motor[motorA]=100;
- motor[motorC]=100;
- }
- motor[motorA]=0;
- motor[motorC]=0;
- }
复制代码上面是一段程序,其实就是让机器人遇到黑线停下来,很易懂。 最近几节课一直都是很简单,都是讲得传感器,下一节课我们将超声波传感器。 过后呢我们会一个语句一个语句分析,把语法都列出来
|