[[2019a/Member]] #define turn_right OnFwd(OUT_C,25);OnRev(OUT_B,15); #define turn_left OnFwd(OUT_B,25);OnRev(OUT_C,15); #define rotate_right OnFwd(OUT_C,20);OnRev(OUT_B,25); #define rotate_left OnFwd(OUT_B,20);OnRev(OUT_C,25); #define go_straight OnFwd(OUT_BC,20); #define go_straight2 OnFwd(OUT_BC,15); #define turn OnRev(OUT_C,25);OnFwd(OUT_B,25);Wait(1500);Off(OUT_BC); #define catch OnRev(OUT_A,25);Wait(500);Off(OUT_A); #define release OnFwd(OUT_A,25);Wait(500);Off(OUT_A); #define osidasi OnFwd(OUT_BC,100);Wait(100);Off(OUT_BC); #define black 20 #define white 50 #define lightgray 40 #define darkgray 28 sub followline_L(int stop_time) { long t0=CurrentTick(); while(CurrentTick()-t0<stop_time){ if(SENSOR_1<black){ rotate_left; }else if(SENSOR_1<darkgray){ turn_left; }else if(SENSOR_1>lightgray){ turn_right; t0=CurrentTick(); }else if(SENSOR_1<35){ go_straight; t0=CurrentTick(); }else{ rotate_right; t0=CurrentTick(); } } Off(OUT_BC); Wait(1000); } sub followline_R(int stop_time) { long t0=CurrentTick(); while(CurrentTick()-t0<stop_time){ if(SENSOR_1<black){ rotate_right; }else if(SENSOR_1<darkgray){ turn_right; }else if(SENSOR_1>lightgray){ turn_left; t0=CurrentTick(); }else if(SENSOR_1<35){ go_straight; t0=CurrentTick(); }else{ rotate_left; t0=CurrentTick(); } } Off(OUT_BC); Wait(1000); } sub followline_R2(int stop_time) { long t0=CurrentTick(); while(CurrentTick()-t0<stop_time){ if(SENSOR_1<black){ rotate_right; t0=CurrentTick(); }else if(SENSOR_1<darkgray){ turn_right; t0=CurrentTick(); }else if(SENSOR_1>lightgray){ turn_left; }else if(SENSOR_1<35){ go_straight2; t0=CurrentTick(); }else{ rotate_left; } } Off(OUT_BC); Wait(2000); } sub Blackto_White() { while(SENSOR_1<darkgray){ OnFwd(OUT_BC,15); } Off(OUT_BC); } sub Whiteto_Black() { while(SENSOR_1>darkgray){ OnFwd(OUT_BC,15); } Off(OUT_BC); } sub Whiteto_Black_R() { while(SENSOR_1>darkgray){ OnFwd(OUT_C,20); OnRev(OUT_B,20); } Off(OUT_BC); } sub Blackto_White_R() { while(SENSOR_1<darkgray){ OnFwd(OUT_C,20); OnRev(OUT_B,20); } Off(OUT_BC); } sub Blackto_White_L() { while(SENSOR_1<lightgray){ OnFwd(OUT_B,20); OnRev(OUT_C,20); } Off(OUT_BC); } sub Whiteto_Black_L() { while(SENSOR_1>black){ OnFwd(OUT_B,20); OnRev(OUT_C,20); } Off(OUT_BC); } task main() { SetSensorLight(S1); followline_R(150); Blackto_White_L(); followline_L(200); Blackto_White_R(); followline_R2(200); catch; turn; followline_R(150); Blackto_White(); followline_L(150); Blackto_White_L(); followline_L(200); Blackto_White(); followline_L(200); Blackto_White(); followline_L(200); Blackto_White(); followline_R(150); Blackto_White(); followline_R(150); release; osidasi; }