[程式]
#define sonic_sensor IN_1
#define touch_sensor IN_2
#define light_sensor IN_3
#define touch SENSOR_2
#define MotorOut OUT_B
#define length 150
long tick;
void WaitSEC3()
{
tick=CurrentTick();
while(CurrentTick()<(tick+3000))
{
PlayTone(880,50);
Wait(950);
}
Wait(1000);
}
task main()
{
SetSensorTouch(touch_sensor);
ResetTachoCount(MotorOut);
SetVolume(4);
SetSensorLight(light_sensor,false);
SetSensorLowspeed(sonic_sensor);
WaitSEC3();
}
task MotorRotateFn()
{
Follows(main);
while(touch==0)
{
RotateMotorPID(MotorOut,10,90,40,40,90); //右轉
Wait(100);
RotateMotorPID(MotorOut,10,-170,40,40,90); //左轉
Wait(100);
RotateMotorPID(MotorOut,10,80,40,40,90); //右轉
}
Off(MotorOut);
StopAllTasks();
}
task DetectFn()
{
Follows(main);
while(true)
{
if(SensorUS(sonic_sensor) <length{
PlayTone(500,50);
SetSensorLight(light_sensor,true);
Wait(50);
SetSensorLight(light_sensor,false);
Wait(50);
}
}
}
PlayTone(500,50);
SetSensorLight(light_sensor,true);
Wait(50);
SetSensorLight(light_sensor,false);
Wait(50);
}
}
}
沒有留言:
張貼留言