[[2005/C5/しょう]]
*詰め合わせ [#m0674b0b]

ライン
 int c=40;
 
 task main ()
 {
   SetSensor (SENSOR_1, SENSOR_LIGHT);
   SetSensor (SENSOR_3, SENSOR_LIGHT);
   while (true)
   {
     while (SENSOR_1<c && SENSOR_3<c)
     {
      OnFwd (OUT_AC);
     }
 
     while (SENSOR_1<c && SENSOR_3>=c) 
     {
       OnFwd (OUT_C);
       OnRev (OUT_A);
     }
 
     while (SENSOR_1>=c && SENSOR_3<c)
     {
       OnFwd (OUT_A);
       OnRev (OUT_C);
     }
       OnFwd (OUT_AC);
   }
 }


light2
 int t=75;
 int m=0;
 int b; 
 
 task main ()
 {
   SetSensor (SENSOR_1, SENSOR_LIGHT);
   ClearTimer (0);
   while (Timer (0) <= t)
   {
   OnFwd (OUT_B);
   until (SENSOR_1 >= m || Timer (0) >= t+1);
   if (Timer (0) >= t+1) goto fine;
   Off (OUT_B);
   ClearTimer (1);
   m=SENSOR_1;
   PlaySound (SOUND_CLICK);
   }
   fine:
   Off (OUT_B);
   b=FastTimer (1)+5;
   PlaySound (SOUND_FAST_UP);
   OnRev (OUT_B);
   Wait (b);
   Off (OUT_B);
 }
 

light3
 int t=50;
 int m=0;
 int b;
 
 task main ()
 {
   SetSensor (SENSOR_3, SENSOR_LIGHT);
   SetSensor (SENSOR_1, SENSOR_LIGHT);
   ClearTimer (0);
   while (Timer (0) <= t)
   {
   OnFwd (OUT_A);
   OnRev (OUT_C);
   if (SENSOR_1 >= m)
    {
    ClearTimer (1);
    m=SENSOR_1;
    PlaySound (SOUND_CLICK);
    }
   }
    Off (OUT_A+OUT_C);
   b=FastTimer (1);
 
   PlaySound (SOUND_FAST_UP);
   OnFwd (OUT_C);
   OnRev (OUT_A);
   Wait (b);
   Off (OUT_A+OUT_C);
   start follow;
   stop main;
 
 }
 
 task follow ()
 {
  start watch;
  while (true)
  {
   if (SENSOR_1 > SENSOR_3)
   {
     Off (OUT_A);
     OnFwd (OUT_C);
   }
   if (SENSOR_1 < SENSOR_3)
   {
     Off (OUT_C);
     OnFwd (OUT_A);
   }
   if (SENSOR_1 == SENSOR_3)
   {
     OnFwd (OUT_AC);
   }
  }
 }
 
 task watch ()
 {
    SetEvent(1, SENSOR_1, EVENT_TYPE_FASTCHANGE);
    SetEvent(2, SENSOR_3, EVENT_TYPE_FASTCHANGE);    
 
   monitor( EVENT_MASK(1) | EVENT_MASK(2) )
    {}
    catch( EVENT_MASK(1) | EVENT_MASK(2) )
    {
     start main;
     stop follow;
    }
 }

wall
 int t;
 int w;
 
 sub yuu ()
 {
    OnFwd(OUT_A+OUT_C);
    until((SENSOR_1==1)&&(SENSOR_3==1));
    OnRev(OUT_A+OUT_C);
    Wait(w);
    OnFwd(OUT_A);
    OnRev(OUT_C);
    Wait(105);
    Off (OUT_A+OUT_C);
 }
 
 sub sho ()
 {
   ClearTimer (0);
 
   while (Timer (0) < t)
   {
 
     while (SENSOR_1==1 && SENSOR_3==0)
     {
       Off (OUT_A+OUT_C);
       OnFwd (OUT_A+OUT_C);
     }
 
     while (SENSOR_1==0 && SENSOR_3==0)
     {
       Off (OUT_A+OUT_C); 
       OnFwd (OUT_C);
       OnRev (OUT_A);
       Wait (10);
       OnFwd (OUT_A+OUT_C);
       Wait (10);
     }
 
     if (SENSOR_1==1 && SENSOR_3==1)
     {
       OnRev (OUT_A+OUT_C);
       Wait (0);
       OnFwd (OUT_A);
       OnRev (OUT_C);
       Wait (130);
       Off (OUT_A+OUT_C);
     }
   } 
 
   Off (OUT_A+OUT_C);
 }
 
 task main ()
 {
   SetSensor (SENSOR_1, SENSOR_TOUCH); //left
   SetSensor (SENSOR_3, SENSOR_TOUCH); //right
   w=5;
   yuu();
   w=50;
   yuu();
   OnFwd (OUT_A+OUT_C);
   Wait (330);
   OnFwd (OUT_C);
   OnRev (OUT_A);
   Wait (90);
   OnFwd (OUT_A+OUT_C);
   until (SENSOR_1==1 && SENSOR_3==1);
   t=160;
   sho();
   w=5;
   yuu();
   yuu();
   OnFwd (OUT_A+OUT_C);
   Wait(340);
   t=1000;
   sho();
   Off (OUT_A+OUT_C);
 
 }


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