[[2006a/A4]]


*何となくプログラム [#e9e47f7e]

*明るいところを探すプログラム [#acaaa788]
 task main(){
 SetSensor(SENSOR_1,SENSOR_LIGHT);
 int max=0,maxtime=0;
 ClearTimer(0);
     while(FastTimer(0)<=460){
           if(max<=SENSOR_1){
               max=SENSOR_1;
               maxtime=FastTimer(0);
                           }
           OnFwd(OUT_A);
           OnRev(OUT_C);
                             }
           ClearTimer(1);
           Off(OUT_A+OUT_C);
           Wait(30);
           maxtime=460-maxtime;
           OnRev(OUT_A);
           OnFwd(OUT_C);
           maxtime=maxtime-FastTimer(1);
           Wait(maxtime);
           Off(OUT_A+OUT_C);
            }


**光源を追いかけるプログラム [#jabd1c4e]
- まだ音を出せませんが、我ながらなかなかのものかと
 // programing :Taro horikawa
 
 #define S1 SENSOR_1
 #define S2 SENSOR_2
 #define S3 SENSOR_3
 #define C 43
 #define F_L OnFwd(OUT_A)
 #define F_R OnFwd(OUT_C)
 #define R_L OnRev(OUT_A)
 #define R_R OnRev(OUT_C)
 
 #define DO 523
 #define RE 587
 #define MI 659
 #define FA 698
 #define SO 784
 
 task music1(){
    while(true){
    
                        }
                    }
                   
  task music2(){
    while(true){
   
                   }
                    }
 
 task main(){
              SetPower(OUT_A,10);
              SetPower(OUT_C,10);
 SetSensor(S1,SENSOR_LIGHT);
 SetSensor(S3,SENSOR_LIGHT);
 int Lmax=0,Rmax=0,Cmax=0,Ltime=0,Rtime=0,Ctime=0;
 Wait(70);
      ClearTimer(0);
      while(FastTimer(0)<=430){
       
          if(Lmax<=S1){
                Lmax=S1;
                Ltime=FastTimer(0);
                             }
                             
          if(Rmax<=S3){
                Rmax=S3;
                Rtime=FastTimer(0);
                             }
           OnFwd(OUT_A);
           OnRev(OUT_C);
       
                                           }
           Off(OUT_A+OUT_C);
           Wait(30);
       Ctime=430 - (Rtime+Ltime)/2;
           OnFwd(OUT_C);
           OnRev(OUT_A);
           Wait(Ctime);
           Off(OUT_A+OUT_C);
           Cmax=(Lmax+Rmax)/2;
           
      while(true){
 
 if(S1>Cmax-13 || S3>Cmax-13){
     
         if((S1<=S3+5) && (S1>=S3-5)){
              SetPower(OUT_A,10);
              SetPower(OUT_C,10);
                                                     }
         if(S1<=S3-6){
          Off(OUT_C);
             Wait(5);
              SetPower(OUT_A,10);
              SetPower(OUT_C,3);
         Lmax=S1;
         Rmax=S3;
                           }
         if(S3<=S1-6){
          Off(OUT_A);
             Wait(5);
              SetPower(OUT_A,3);
              SetPower(OUT_C,10);
         Lmax=S1;
         Rmax=S3;
                           }
                                  
                                             
             F_R;
             F_L;
             
                                             }
             
          if(S1<=Cmax-13 && S3<=Cmax-13){
     
              SetPower(OUT_A,10);
              SetPower(OUT_C,10);
              
                if(Lmax>=Rmax){
   until((S1<=S3+6) && (S1>=S3-6) && (S1>Cmax-13 || S3>Cmax-13)){
                           F_R;R_L;
                                                                                                }
                                       }
                if(Lmax<Rmax){
   until((S1<=S3+6) && (S1>=S3-6) && (S1>Cmax-13 || S3>Cmax-13)){
                           F_L;R_R;
                                                                                              }
                                       }
                                       
                                    }
      
                      }
      
 
                }

**音付き1 [#wcd50d88]
 // programing :Taro horikawa
 
 #define S1 SENSOR_1
 #define S2 SENSOR_2
 #define S3 SENSOR_3
 #define C 43
 #define F_L OnFwd(OUT_A)
 #define F_R OnFwd(OUT_C)
 #define R_L OnRev(OUT_A)
 #define R_R OnRev(OUT_C)
 
 #define Do 523
 #define Re 587
 #define Mi 659
 #define Fa 698
 #define Sol 784
 
 task music1()
 {
    while (true)
    {
        PlayTone(Do,60); Wait(20);
        PlayTone(Fa,40); Wait(20);
        PlayTone(Fa,130); Wait(200);
                                        
        PlayTone(Fa,60); Wait(20);                                        
        PlayTone(Sol,40); Wait(20);
        PlayTone(Sol,40); Wait(20);       
        PlayTone(Sol,120); Wait(20);
        Wait(200);
        
        
    }
 }
          
 task main(){
 
              SetPower(OUT_A,10);
              SetPower(OUT_C,10);
 SetSensor(S1,SENSOR_LIGHT);
 SetSensor(S3,SENSOR_LIGHT);
 SetSensor(S2,SENSOR_TOUCH);
 int Lmax=0,Rmax=0,Cmax=0,Ltime=0,Rtime=0,Ctime=0;
 Wait(70);
      ClearTimer(0);
      while(FastTimer(0)<=430){
       
          if(Lmax<=S1){
                Lmax=S1;
                Ltime=FastTimer(0);
                             }
                             
          if(Rmax<=S3){
                Rmax=S3;
                Rtime=FastTimer(0);
                             }
           OnFwd(OUT_A);
           OnRev(OUT_C);
       
                                           }
           Off(OUT_A+OUT_C);
           Wait(30);
       Ctime=430 - (Rtime+Ltime)/2;
           OnFwd(OUT_C);
           OnRev(OUT_A);
           Wait(Ctime);
           Off(OUT_A+OUT_C);
           Cmax=(Lmax+Rmax)/2;
           
      while(true){
 
 if(S1>Cmax-12 || S3>Cmax-12){
     
         if((S1<=S3+5) && (S1>=S3-5)){
              SetPower(OUT_A,10);
              SetPower(OUT_C,10);
                                                     }
         if(S1<=S3-6){
          Off(OUT_C);
             Wait(5);
              SetPower(OUT_A,10);
              SetPower(OUT_C,3);
         Lmax=S1;
         Rmax=S3;
                           }
         if(S3<=S1-6){
          Off(OUT_A);
             Wait(5);
              SetPower(OUT_A,3);
              SetPower(OUT_C,10);
         Lmax=S1;
         Rmax=S3;
                           }
                                  
                                             
             F_R;
             F_L;
             
                                             }
             
          if(S1<=Cmax-12 && S3<=Cmax-12){
              SetPower(OUT_A,10);
              SetPower(OUT_C,10);
               start music1;
 until((S1<=S3+6) && (S1>=S3-6) && (S1>Cmax-12 || S3>Cmax-12)){
                          if(Lmax>=Rmax){
                          F_R;R_L;
                                                    }
                          if(Lmax<Rmax){
                          F_L;R_R;
                                                  }
                                                                                                              }
                                       
                                                              }
            stop music1;
      
                      }
 
 
                }





 #define C  523
 #define Ces 554
 #define D  587
 #define Des 622
 #define E  659
 #define F  698
 #define Fes 740
 #define G 784
 #define Ges 831
 #define A 880
 #define Aes 932
 #define H 988
 #define C8  1047
 #define Ces8 1109
 #define D8 1175
 #define Des8 1245
 #define E8 1319
 #define F8 1397
 #define  Fes8 1480
 #define  G8 1568
 #define  Ges8 1661
 #define  A8 1760
 #define  Aes8 1865 

 task main()
 {while(true)
 {

 PlayTone(C,58); Wait(60);
 PlayTone(F,38); Wait(40);
 PlayTone(C,8); Wait(10);
 PlayTone(F,18); Wait(20);
 PlayTone(Ges,58); Wait(60);
 PlayTone(F,58); Wait(60);

 PlayTone(Ges,37); Wait(39);
 PlayTone(F,8); Wait(10);
 PlayTone(Ges,18); Wait(20);
 PlayTone(C8,58); Wait(60);
 PlayTone(Ges,58); Wait(60);
 
 PlayTone(C8,37); Wait(39);
 PlayTone(Ges,8); Wait(10);
 PlayTone(C8,18); Wait(20);
 PlayTone(Des8,58); Wait(60);
 PlayTone(Des,58); Wait(60);  

 PlayTone(Ges,38); Wait(40);
 PlayTone(Des,8); Wait(10);
 PlayTone(Ges,32); Wait(34);
 PlayTone(C8,120); Wait(120);



 Wait(200);


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