[[2017a/Member]] ライントレース #define senkai_left OnRev(OUT_C);OnFwd(OUT_A);//左旋回 #define senkai_right OnFwd(OUT_C);OnRev(OUT_A); //右旋回 #define turn_left Off(OUT_C);OnFwd(OUT_A);//左折 #define turn_right OnFwd(OUT_C);Off(OUT_A);//右折 #define fwd OnFwd(OUT_AC);//直進 #define SIGNALON 11 #define SIGNALOFF 12 #define owari Wait(300);OnRev(OUT_AC);Wait(250);Off(OUT_AC); void go_fwd(int time) { fwd; Wait(time); Off(OUT_AC); } sub usetu() { turn_right; Wait(240); Off(OUT_C); senkai_right; Wait(50); Off(OUT_AC); OnRev(OUT_AC); Wait(30); Off(OUT_AC); } sub sasetu() { turn_left; Wait(210); Off(OUT_A); senkai_left; Wait(20); Off(OUT_AC); OnRev(OUT_AC); Wait(30); Off(OUT_AC); } sub naname_usetu() { OnFwd(OUT_C); Off(OUT_A); Wait(180); Off(OUT_C); OnRev(OUT_AC); Wait(30); Off(OUT_AC); } sub line_trace() { SetSensor(SENSOR_1, SENSOR_LIGHT); //右 SetSensor(SENSOR_3, SENSOR_LIGHT); //左 ClearTimer(0); PlaySound(SOUND_CLICK); while(FastTimer(0)<11){ if(SENSOR_1>=49&&SENSOR_3>=55){ fwd; ClearTimer(0); }else if(SENSOR_3>=50){ turn_right; ClearTimer(0); }else if(SENSOR_1>=40){ turn_left; ClearTimer(0); }else if(SENSOR_3>=48){ senkai_right; ClearTimer(0); }else if(SENSOR_1>=38){ senkai_left; ClearTimer(0); }else if(SENSOR_1>=30){ Off(OUT_AC); PlaySound(SOUND_LOW_BEEP); }else if(SENSOR_3>=30){ Off(OUT_AC); PlaySound(SOUND_LOW_BEEP); }else{ fwd; Wait(30); Off(OUT_AC); } } Off(OUT_AC); PlaySound(SOUND_CLICK); } void line_trace_2(int time) { SetSensor(SENSOR_1, SENSOR_LIGHT); //右 SetSensor(SENSOR_3, SENSOR_LIGHT); //左 ClearTimer(0); ClearTimer(1); PlaySound(SOUND_CLICK); while(FastTimer(0)<11&&FastTimer(1)<time){ if(SENSOR_1>=49&&SENSOR_3>=55){ fwd; ClearTimer(0); }else if(SENSOR_3>=50){ turn_right; ClearTimer(0); }else if(SENSOR_1>=40){ turn_left; ClearTimer(0); }else if(SENSOR_3>=48){ senkai_right; ClearTimer(0); }else if(SENSOR_1>=38){ senkai_left; ClearTimer(0); }else if(SENSOR_1>=30){ Off(OUT_AC); PlaySound(SOUND_LOW_BEEP); }else if(SENSOR_3>=30){ Off(OUT_AC); PlaySound(SOUND_LOW_BEEP); }else{ fwd; Wait(30); Off(OUT_AC); } } Off(OUT_AC); } task main() { go_fwd(50); line_trace(); usetu(); repeat(2){ line_trace(); Wait(50); naname_usetu(); Wait(50); } line_trace_2(170); sasetu(); go_fwd(55); Wait(100); line_trace_2(520); go_fwd(55); Wait(400); sasetu(); go_fwd(240); owari; }