2005/C4

左を書く

int penstat=0; task main() {

	penon();
	OnRev(OUT_A+OUT_B);Wait(300);
	penoff();
	Off(OUT_A);Wait(10);
	OnFwd(OUT_A+OUT_B);Wait(10);
	Off(OUT_A);Wait(10);
	penon();
	OnFwd(OUT_A);Wait(300);
	penoff();
	OnRev(OUT_A+OUT_B);Wait(100);
	Off(OUT_A+OUT_B);
	OnFwd(OUT_A);
	penon();
	OnFwd(OUT_B);Wait(100);
	penoff();
	OnRev(OUT_A+OUT_B);Wait(50);
	Off(OUT_A);Wait(80);
	penon();
	OnFwd(OUT_B);Wait(50);
	penoff();
	OnRev(OUT_B);Wait(80);
	OnRev(OUT_A);Wait(80);
	penon();
	OnFwd(OUT_A);Wait(100);
	penoff();
	Off(OUT_A+OUT_B);

} sub penon(){

       if(penstat!=1){
               //Write
               SetPower(OUT_C,3);
               OnFwd(OUT_C);
               Wait(20);
               Float(OUT_C);
               penstat=1;
               Wait(50);
       }

}

sub penoff(){

       if(penstat!=0){
               //Dont Write
               SetPower(OUT_C,4);
               OnRev(OUT_C);
               Wait(10);
               Float(OUT_C);
               penstat=0;
               Wait(50);
       }

} コメントをどうぞ


机の周りを移動する

task main() {

	SetSensor(SENSOR_1, SENSOR_TOUCH);
	SetSensor(SENSOR_3, SENSOR_TOUCH);
	
	OnFwd(OUT_A+OUT_C);
	while(true)
	{
	if((SENSOR_1 == 1) && (SENSOR_3 == 1)){
		OnRev(OUT_A+OUT_C); Wait(20);
		OnFwd(OUT_A); Wait(110);
		OnFwd(OUT_C);
	}
	
	if(SENSOR_1 == 0){
		Off(OUT_A); Wait(4);
		OnFwd(OUT_A);
	}
		
	if(SENSOR_1 == 1){
		Off(OUT_C); Wait(4);
		OnFwd(OUT_C);
		}
	}

} コメントをどうぞ


モーター1個

task main() {

	SetSensor(SENSOR_1, SENSOR_LIGHT);
	
	while(true){
		if(SENSOR_1 < 40){
			OnFwd(OUT_A);
		}else{
			OnRev(OUT_A);
		}
	}

}

光を追いかける

int i; int light_max=0; int time_max=0; task main() {

	SetSensor(SENSOR_1,SENSOR_LIGHT);
	SetSensor(SENSOR_3,SENSOR_LIGHT);
	ClearTimer(0);
	for(i=1; i<=50; i++){
		OnFwd(OUT_A);Wait(10);
		Off(OUT_A);Wait(5);		
		if(SENSOR_1>light_max){
			light_max=SENSOR_1;
			time_max=Timer(0);
			}
		if(SENSOR_3>light_max){
			ligth_max=SENSOR_3;
			time_max=Timer(0);
			}
		}
	Off(OUT_A);Wait(50);
	OnRev(OUT_A);Wait(500-time_max);
	Off(OUT_A);Wait(50);
	while(true){
		if(SENSOR_1>=light_max){
			Off(OUT_A);
			OnFwd(OUT_C);
			}
		if(SENSOR_3>=light_max){
			OnFwd(OUT_A);
			Off(OUT_C);
			}
		}

}

音楽を演奏する

task play_music() {

	while(true)
	{
		PlayTone( 220, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 220, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 220, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 293, SIXTEENTH_NOTE );
		Wait( SIXTEENTH_NOTE );
		PlayTone( 195, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 195, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 195, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 261, SIXTEENTH_NOTE );
		Wait( SIXTEENTH_NOTE );
		PlayTone( 220, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 220, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 220, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 293, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 329, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 369, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 391, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 440, SIXTEENTH_NOTE );
		Wait( SIXTEENTH_NOTE );
		PlayTone( 220, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 220, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 220, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 293, SIXTEENTH_NOTE );
		Wait( SIXTEENTH_NOTE );
		PlayTone( 220, SIXTEENTH_NOTE );
		Wait( SIXTEENTH_NOTE );
		PlayTone( 195, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 184, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 164, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 293, SIXTEENTH_NOTE );
		Wait( SIXTEENTH_NOTE );
		PlayTone( 220, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 195, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 184, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 164, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 293, SIXTEENTH_NOTE );
		Wait( SIXTEENTH_NOTE );
		PlayTone( 220, SIXTEENTH_NOTE );
		Wait( SIXTEENTH_NOTE );
		PlayTone( 195, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 184, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 195, EIGHTH_NOTE );
		Wait( EIGHTH_NOTE );
		PlayTone( 164, SIXTEENTH_NOTE );
		Wait( SIXTEENTH_NOTE );
	}

}

		

task main() {

	start play_music;
	ClearTimer(0);
	while(Timer(0)<=100){SendMessage(1);}
	while(Timer(0)<=200){SendMessage(2);}
	while(Timer(0)<=300){SendMessage(3);}
	stop play_music;

}

音楽に合わせて動く

task main() {

	while(true)
	{
		ClearMessage();
		until(Message()!=0);
		if(Message()==1)
			OnRev(OUT_A+OUT_C);
		if(Message()==2)OnFwd(OUT_A);
		if(Message()==3)
			OnFwd(OUT_A+OUT_C);Wait(40);
			Off(OUT_A+OUT_C);
	}

}

アームの上下

#define A OUT_A

#define B OUT_B

task main()

{

	ClearMessage();
	until(Message()!=0);
	
	if(Message()==1)
	{
	OnFwd(A);
	SetPower(A,OUT_LOW);
	Wait(100);
	Float(A);
	OnFwd(B);
	SetPower(B,OUT_LOW);
	OnRev(A);
	SetPower(A,OUT_LOW);
	Wait(100);
	Float(A);
	SendMessage(1);Wait(200);
	}
	if(Message()==2)
	{	
	OnFwd(A);
	SetPower(A,OUT_LOW);
	Wait(100);
	Float(A);
	OnRev(B);
	SetPower(B,OUT_LOW);
	OnRev(A);
	SetPower(A,OUT_LOW);
	Wait(100);
	Float(A);
	SendMessage(2);Wait(200);
	}

}


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2006-02-08 (水) 18:21:24