目次
#contents
*障害物にあたると向きを変えるロボのプログラム [#j0b86d0c]
 task main()
 {
    SetSensor(SENSOR_1,SENSOR_TOUCH); 
      while  (1+1==2)
       { 
       OnFwd(OUT_A+OUT_C);              
         until (SENSOR_1 == 1);           
         OnRev(OUT_A+OUT_C);
          Wait(80);
         OnFwd(OUT_C);
         OnRev(OUT_A);
         Wait(90);
       }
                  
 } 
*光の方を向くロボット(黒板の写し) [#d3cac655]
 #define stop_turning Off(OUT_A+OUT_C);
 #define turn_right OnFwd(OUT_A);OnRev(OUT_C);
 #define turn_left OnFwd(OUT_C);OnRev(OUT_A);
 #define TURN_TIME 400
 task main()
 {
 SetSensor(SENSOR_1,SENSOR_LIGHT);
 int light_max=0,time_max=0;
 turn_right;
 ClearTimer(0);
 while(FastTimer(0)<TURN_TIME){
 if(SENSOR_1>light_max){
 light_max=SENSOR_1;
 time_max=FastTimer(0);
 }
 }
 stop_turning;
 Wait(100);
 turn_left;
 Wait(TURN_TIME-time_max);
 stop_turning;
 }

*光に向かっていくプログラム(のはず) [#ba4ab326]
 #define stop_turning Off(OUT_A+OUT_C);
 #define go_turning OnFwd(OUT_A+OUT_C);
 #define turn_right OnFwd(OUT_A);OnRev(OUT_C);
 #define turn_left OnFwd(OUT_C);OnRev(OUT_A);
 #define TURN_TIME 400
 task main()
 {
 while(1+1==2);
 {
 SetSensor(SENSOR_1,SENSOR_LIGHT);
 int light_max=0,time_max=0;
 
 turn_right;
 ClearTimer(0);
 while(FastTimer(0)<TURN_TIME){
 if(SENSOR_1>light_max){
 light_max=SENSOR_1;
 time_max=FastTimer(0); 
 }
 }
 stop_turning;
 Wait(100);
 turn_left;
 Wait(TURN_TIME-time_max);
 go_turning;
 Wait(80);
 }
 }


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS