|
楼主 |
发表于 2013-7-5 21:30:15
|
显示全部楼层
现在倒是可以跳出了,但无法到刚刚跳出的位置重新开始,很是不解!
程序如下:
#pragma config(Sensor, S1, touch_right, sensorTouch)
#pragma config(Sensor, S2, light, sensorLightActive)
#pragma config(Sensor, S4, touch_left, sensorTouch)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
int n,i,m;
void test_0()
{
nMotorEncoder[motorB]=0;
nMotorEncoder[motorC]=0;
while(nMotorEncoder[motorB]<1000)
{
motor[motorB]=50;
motor[motorC]=50;
}
motor[motorB]=0;
motor[motorC]=0;
}
void test_1()
{
nMotorEncoder[motorB]=0;
nMotorEncoder[motorC]=0;
while(nMotorEncoder[motorB]<1000)
{
motor[motorB]=50;
motor[motorC]=0;
}
motor[motorB]=0;
motor[motorC]=0;
}
void test_2()
{
motor[motorB]=0;
motor[motorC]=50;
wait1Msec(3000);
motor[motorB]=0;
motor[motorC]=0;
}
void test_3()
{
motor[motorB]=50;
motor[motorC]=-50;
wait1Msec(3000);
motor[motorB]=0;
motor[motorC]=0;
}
//****************************************************************************//
task sp0()
{
while(true)
{
if(SensorValue(S1)==1)
{
n=n+1;
switch (n)
{
case 1:
{
wait1Msec(100);
test_0();
break;
}
case 2:
{
wait1Msec(100);
test_1();
break;
}
case 3:
{
wait1Msec(100);
test_2();
break;
}
case 4:
{
wait1Msec(100);
test_3();
break;
}
}
}
else
{
wait1Msec(1);
}
}
}
//**********************************************************//
task sp1()
{
while(true)
{
i=0;
if(SensorValue(S4)==1)
{
i++;
m++;
}
if(i==1)
{
motor[motorB]=0;
motor[motorC]=0;
StopTask(sp0);
wait1Msec(10);
n=n-1;
StartTask(sp0);
}
}
}
//****************************************************//
task main()
{
n=0;m=0;
StartTask(sp0);
StartTask(sp1);
while(true)
{
}
}
|
|