戻る

プログラムメモ

#define getta_time 200

#define otosu_time1 200

#define otosu_time2 100

#define green_white 48

#define brack_green 38

int Mes;

sub Getta(){

	OnFwd(OUT_A);
	Wait(getta_time);
	Off(OUT_A);
	SendMessage(1);
	}

sub otosu(){

	OnRev(OUT_A);
	Wait(otosu_time1);
	Off(OUT_A);
	OnFwd(OUT_C);
	Wait(otosu_time2);
	Off(OUT_C);
	}

task main(){

	Getta();
	
	
	while(true){
	while(true){
		ClearMessage();
		until (Message() != 0);
		
		if(Message() == 5)Mes=5; break;//otosite
		if(Message() == 6)Mes=6; break;//totte
		if(Message() == 7)Mes=7; break;//totte
		}
		
		if(Mes==5){
			otosu();
			
			}
		if(Mes==6){
			Getta();
			
			
			}
		if(Mes==7){
			SetSensor(SENSOR_1,SENSOR_LIGHT);
			
			if((SENSOR_1 <= green_white) && (SENSOR_1 >= brack_green)){
				SendMessage(2);Wait(500);
				}
			if(SENSOR_1 > green_white){
				SendMessage(3);Wait(500);
				}
			if(SENSOR_1 < brack_green) {
				SendMessage(4);Wait(500);
				}
			
			}
		}

}

			

#define line 47

#define 200//90do

#define go_time 100//boxmade

#define box_time 50//berutokonbea

int Mes; int t; sub turn_left(){

	OnFwd(OUT_C); Off(OUT_A);
	Wait(10);
	until((SENSOR_1 >  line) && (SENSOR_3 > line));
	OnFwd(OUT_C);
	until(SENSOR_1 < line);
	OnFwd(OUT_A+OUT_C);
	until(SENSOR_3 <  line) ;
	Off(OUT_A+OUT_C);

} sub turn_right(){

	OnFwd(OUT_A); Off(OUT_C);
	Wait(10);
	until((SENSOR_1 >  line) && (SENSOR_3 > line));
	OnFwd(OUT_A);
	until(SENSOR_3 < line);
	OnFwd(OUT_A+OUT_C);
	until(SENSOR_1 <  line);
	Off(OUT_A+OUT_C);

}

sub line_go(){

	SetSensor(SENSOR_1,SENSOR_LIGHT);//left
	SetSensor(SENSOR_3,SENSOR_LIGHT);//right 
	
	OnFwd(OUT_A+OUT_C);
	Wait(50);
	
	while(true){
	if((SENSOR_1 <  line) && (SENSOR_3 > line)){
		OnFwd(OUT_C);
		Off(OUT_A);
		until(SENSOR_1 > line);
		}
	
	if((SENSOR_1 > line) && (SENSOR_3 < line)){
		OnFwd(OUT_A);
		Off(OUT_C);
		until(SENSOR_3 > line);
		}
		
	if((SENSOR_1 < line) && (SENSOR_3 < line)){
		Off(OUT_A+OUT_C);
		}
	
	else{
		OnFwd(OUT_A+OUT_C);
		}
	}

} sub line_back(){

	SetSensor(SENSOR_1,SENSOR_LIGHT);//left
	SetSensor(SENSOR_3,SENSOR_LIGHT);//right 
	
	OnRev(OUT_A+OUT_C);
	Wait(50);	
	while(true){
	if((SENSOR_1 <  line) && (SENSOR_3 > line)){
		OnRev(OUT_C);
		Off(OUT_A);
		until(SENSOR_1 > line);
		}
	
	if((SENSOR_1 > line) && (SENSOR_3 < line)){
		OnRev(OUT_A);
		Off(OUT_C);
		until(SENSOR_3 > line);
		}
		
	if((SENSOR_1 < line) && (SENSOR_3 < line)){
		Off(OUT_A+OUT_C);
		}
	
	else{
		OnRev(OUT_A+OUT_C);
		}
	}

}

task main() {

	SetSensor(SENSOR_1,SENSOR_LIGHT);
	SetSensor(SENSOR_3,SENSOR_LIGHT);
	while(true){
		ClearMessage();
		until (Message() != 0);
		
		if(Message() == 1)Mes=1; break;//toriawatta
		if(Message() == 2)Mes=2; break;//green dayo
		if(Message() == 3)Mes=3; break;//white dayo
		if(Message() == 4)Mes=4; break;//brack dayo
		}
		
	if(Mes==1){
		OnRev(OUT_A+OUT_C);
		until((SENSOR_1 < line) && (SENSOR_3 < line));
		OnFwd(OUT_C); OnRev(OUT_A);
		until((SENSOR_1 > line) && (SENSOR_3 > line));
		repeat(2){
			line_go();
		}
		turn_right();
		OnFwd(OUT_A+OUT_C);
		until(SENSOR_1 < line);
		turn_left();
		line_go();
	}
	
	
	repeat(3){
		SendMessage(7);
		while(true){
		ClearMessage();
		until (Message() != 0);
		
		if(Message() == 1)Mes=1; break;//toriawatta
		if(Message() == 2)Mes=2; break;//green dayo
		if(Message() == 3)Mes=3; break;//white dayo
		if(Message() == 4)Mes=4; break;//brack dayo
		}
		if(Mes == 2){//green
			turn_left();
			OnRev(OUT_A+OUT_C);Wait(go_time);
			SendMessage(5); Wait(500);//owattayo
			OnFwd(OUT_A+OUT_C);Wait(go_time);
			turn_right();
			OnFwd(OUT_B);Wait(box_time);
		}
		else if(Mes == 3){//white
			line_go();
			turn_left();
			OnRev(OUT_A+OUT_C);Wait(go_time);
			SendMessage(5); Wait(500);//owwatayo
			OnFwd(OUT_A+OUT_C);Wait(go_time);
			turn_right();
			line_back();
			OnFwd(OUT_B);Wait(box_time);
		}
		else if(Mes == 4){//brack
			line_go();
			line_go();
			turn_left();
			OnRev(OUT_A+OUT_C);Wait(go_time);
			SendMessage(5); Wait(500);//owattayo
			OnFwd(OUT_A+OUT_C);Wait(go_time);
			turn_right();
			line_back();
			line_back();
			OnFwd(OUT_B);Wait(box_time);
		}
	}
	line_back();//go home
	turn_left();
	
	SendMessage(6); Wait(500);//totte
	
	while(true){
		ClearMessage();
		until (Message() != 0);
		
		if(Message() == 1)Mes=1; break;//toriawatta
		if(Message() == 2)Mes=2; break;//green dayo
		if(Message() == 3)Mes=3; break;//white dayo
		if(Message() == 4)Mes=4; break;//brack dayo
		}
	if(Mes==1){
		OnFwd(OUT_A+OUT_C);
		until((SENSOR_1 < line) && (SENSOR_3 < line));
		OnFwd(OUT_A); OnRev(OUT_C);
		until((SENSOR_1 > line) && (SENSOR_3 > line));
		
		line_go();
		
		OnFwd(OUT_A); OnRev(OUT_C);
		Wait();
		OnFwd(OUT_A+OUT_C);
		until(SENSOR_1 < line);
		turn_left();
		line_go();
	}
	
	repeat(3){
				SendMessage(7);
		while(true){
		ClearMessage();
		until (Message() != 0);
		
		if(Message() == 1)Mes=1; break;//toriawatta
		if(Message() == 2)Mes=2; break;//green dayo
		if(Message() == 3)Mes=3; break;//white dayo
		if(Message() == 4)Mes=4; break;//brack dayo
		}
		if(Mes == 2){//green
			turn_left();
			OnRev(OUT_A+OUT_C);Wait(go_time);
			SendMessage(5); Wait(500);//owattayo
			OnFwd(OUT_A+OUT_C);Wait(go_time);
			turn_right();
			OnFwd(OUT_B);Wait(box_time);
		}
		else if(Mes == 3){//white
			line_go();
			turn_left();
			OnRev(OUT_A+OUT_C);Wait(go_time);
			SendMessage(5); Wait(500);//owwatayo
			OnFwd(OUT_A+OUT_C);Wait(go_time);
			turn_right();
			line_back();
			OnFwd(OUT_B);Wait(box_time);
		}
		else if(Mes == 4){//brack
			line_go();
			line_go();
			turn_left();
			OnRev(OUT_A+OUT_C);Wait(go_time);
			SendMessage(5); Wait(500);//owattayo
			OnFwd(OUT_A+OUT_C);Wait(go_time);
			turn_right();
			line_back();
			line_back();
			OnFwd(OUT_B);Wait(box_time);
		}
	}
	line_back();//go home
	turn_left();

}

  • ロボコン
    #define line 47
    #define turn_time 200
    #define go_time 100
    #define box_time 50
    int move_time;
    int Mes;
    sub turn_left(){
    	OnFwd(OUT_C); OnRev(OUT_A);
    }
    sub turn_right(){
    	OnFwd(OUT_A); OnRev(OUT_C);
    }
    
    sub wall_go(){
    	
    
    
    }
    
    sub line_go(){
    	SetSensor(SENSOR_1,SENSOR_LIGHT);//left
    	SetSensor(SENSOR_3,SENSOR_LIGHT);//right 
    	
    	OnFwd(OUT_A+OUT_C);
    	
    	while(true){
    	if((SENSOR_1 <  line) && (SENSOR_3 > line)){
    		OnFwd(OUT_C);
    		Off(OUT_A);
    		until(SENSOR_1 > line);
    		}
    	
    	if((SENSOR_1 > line) && (SENSOR_3 < line)){
    		OnFwd(OUT_A);
    		Off(OUT_C);
    		until(SENSOR > line);
    		}
    		
    	if((SENSOR_1 < line) && (SENSOR_3 < line)){
    		break;
    		}
    	
    	else{
    		OnFwd(OUT_A+OUT_C);
    		}
    	}
    }
    sub line_back(){
    	SetSensor(SENSOR_1,SENSOR_LIGHT);//left
    	SetSensor(SENSOR_3,SENSOR_LIGHT);//right 
    	
    	OnRev(OUT_A+OUT_C);
    	
    	while(true){
    	if((SENSOR_1 <  line) && (SENSOR_3 > line)){
    		OnRev(OUT_C);
    		Off(OUT_A);
    		until(SENSOR_1 > line);
    		}
    	
    	if((SENSOR_1 > line) && (SENSOR_3 < line)){
    		OnRev(OUT_A);
    		Off(OUT_C);
    		until(SENSOR > line);
    		}
    		
    	if((SENSOR_1 < line) && (SENSOR_3 < line)){
    		break;
    		}
    	
    	else{
    		OnRev(OUT_A+OUT_C);
    		}
    }
    
    sub GetMessage(){
    	while(true){
    		ClearMessage();
    		until (Message() != 0);
    		
    		if(Message() == 1)Mes=1;//toriawatta
    		if(Message() == 2)Mes=2;//green dayo
    		if(Message() == 3)Mes=3;//white dayo
    		if(Message() == 4)Mes=4;//brack dayo
    		}
    
    }
    sub bunbetu(){
    	repeat(3){
    		GetMessage();
    		if(Mes == 2){//green
    			line_go();
    			turn_right(turn_time);
    			OnFwd(OUT_A+OUT_C);Wait(go_time);
    			SendMessage(5); Wait(500);//owattayo
    			OnRev(OUT_A+OUT_C);Wait(go_time);
    			turn_left(turn_time);
    			line_back();
    			OnFwd(OUT_B);Wait(box_time);
    		}
    		else if(Mes == 3){//white
    			line_go();
    			line_go();
    			turn_right(turn_time);
    			OnFwd(OUT_A+OUT_C);Wait(go_time);
    			SendMessage(5); Wait(500);//owwatayo
    			OnRev(OUT_A+OUT_C);Wait(go_time);
    			turn_left(turn_time);
    			line_back();
    			line_back();
    			OnFwd(OUT_B);Wait(box_time);
    		}
    		else if(Mes == 4){//brack
    			line_go();
    			line_go();
    			line_go();
    			turn_right(turn_time);
    			OnFwd(OUT_A+OUT_C);Wait(go_time);
    			SendMessage(5); Wait(500);//owattayo
    			OnRev(OUT_A+OUT_C);Wait(go_time);
    			turn_left(turn_time);
    			line_back();
    			line_back();
    			line_back();
    			OnFwd(OUT_B);Wait(box_time);
    		}
    	}
    
    }
    task main(){
    	SetSensor(SENSOR_1,SENSOR_LIGHT);
    	SetSensor(SENSOR_3,SENSOR_LIGHT);
    
    	GetMessage();
    	if(Mes==1){
    		OnFwd(OUT_A+OUT_C)
    		until((SENSOR_1 < line) && (SENSOR_3 < line));
    		turn_right();
    		until((SENSOR_1 > line) && (SENSOR_3 > line));
    		repeat(3){
    			line_go();
    		}
    		turn_right();
    		Wait(turn_time);
    		OnFwd(OUT_A+OUT_C);
    		until(SENSOR_1 < line);
    		turn_left();
    		Wait(turn_time);
    		line_go();
    	}
    	
    	bunbetu();
    
    	line_back();//go home
    	turn_left(turn_time);
    	
    	SendMessage(6); Wait(500);//totte
    	
    	GetMessage();
    	if(Mes==1){
    		OnFwd(OUT_A+OUT_C)
    		until((SENSOR_1 < line) && (SENSOR_3 < line));
    		turn_right();
    		until((SENSOR_1 > line) && (SENSOR_3 > line));
    		
    		line_go();
    		
    		turn_right();
    		Wait(turn_time);
    		OnFwd(OUT_A+OUT_C);
    		until(SENSOR_1 < line);
    		turn_left();
    		Wait(turn_time);
    		line_go();
    	}
    	
    	bunbetu();
    
    	line_back();//go home
    	turn_left(turn_time);
    
    }
  • スケーターズワルツ
    #define Do 523
    #define Re 587
    #define Mi 659
    #define Fa 698
    #define So 784
    #define Ra 880
    #define Si 988
    #define Doo 1047
    #define Ree 1175
    
    task play_music()
    { 
    
    	while(true){
    		PlayTone(Mi,120);Wait(120);
    		
    		PlayTone(So,80);Wait(80);
    		PlayTone(Ra,40); Wait(45);
    		
    		PlayTone(Ra,240);Wait(245);
    		
    		PlayTone(Fa,120);Wait(120);
    		
    		PlayTone(Ra,80);Wait(80);
    		PlayTone(Si,40);Wait(45);
    		
    		PlayTone(Si,240);Wait(245);
    		
    		PlayTone(Ree,120);Wait(120);
    
    		PlayTone(Doo,80);Wait(80);
    		PlayTone(Mi,40);Wait(45);
    		
    		PlayTone(So,120);Wait(120);
    		
    		PlayTone(Fa,80);Wait(80);
    		PlayTone(Mi,40);Wait(45);
    		
    		PlayTone(Mi,120);Wait(120);
    		
    		PlayTone(Re,120);Wait(120);
    		
    		PlayTone(Do,150);Wait(160);
    		
    		PlayTone(So,15);Wait(20);
    		PlayTone(Doo,15);Wait(20);
    		
    		PlayTone(Ra,15);Wait(20);
    		PlayTone(Doo,15);Wait(20);
    		PlayTone(So,15);Wait(20);
    		PlayTone(Doo,15);Wait(20);
    		PlayTone(Ra,15);Wait(20);
    		PlayTone(Doo,15);Wait(20);
    		
    		PlayTone(So,15);Wait(20);
    		PlayTone(Doo,15);Wait(20);
    		PlayTone(Ra,15);Wait(20);
    		PlayTone(Doo,15);Wait(20);
    		PlayTone(So,15);Wait(20);
    		PlayTone(Doo,15);Wait(20);
    		
    		PlayTone(Ra,15);Wait(20);
    		PlayTone(Doo,15);Wait(20);
    		PlayTone(So,40);Wait(40);
    		
    		PlayTone(Si,30);Wait(40);
    		PlayTone(Si,40);Wait(40);
    		
    		PlayTone(So,40);Wait(40);
    		PlayTone(Si,30);Wait(40);
    		PlayTone(Si,40);Wait(40);
    		
    		PlayTone(So,15);Wait(20);
    		PlayTone(Ree,15);Wait(20);
    		PlayTone(Ra,15);Wait(20);
    		PlayTone(Ree,15);Wait(20);
    		PlayTone(So,15);Wait(20);
    		PlayTone(Ree,15);Wait(20);
    		
    		PlayTone(Ra,15);Wait(20);
    		PlayTone(Ree,15);Wait(20);
    		PlayTone(So,15);Wait(20);
    		PlayTone(Ree,15);Wait(20);
    		PlayTone(Ra,15);Wait(20);
    		PlayTone(Ree,15);Wait(20);
    		
    		PlayTone(So,40);Wait(40);
    		PlayTone(Doo,30);Wait(40);
    		PlayTone(Doo,40);Wait(40);
    		
    		PlayTone(So,40);Wait(40);
    		PlayTone(Doo,30);Wait(40);
    		PlayTone(Doo,40);Wait(40);
    	}
    }
    
    task main(){
    	start play_music ;
    	
    }
  • 一番明るい方を向くプログラム
int LIGHT_=0;	//一番明るいところの値を入れる
int TIME_LIGHT=0;//一番明るいところまで回るまでの時間
int RUN_TIME=450;//一回転する時間

task main(){

	SetSensor(SENSOR_1, SENSOR_LIGHT);
	ClearTimer(0);
	
	while (FastTimer(0) <= RUN_TIME) { //一回転するまで繰り返す
		if ( SENSOR_1 > LIGHT_ ) { //もし今まで記録した値より明るかったら
			LIGHT_ = SENSOR_1 ; //関数にその明るさを記録
			TIME_LIGHT = FastTimer(0); //関数にそのときまでの時間を記録
		}
		OnFwd(OUT_A);
		OnRev(OUT_C);
	}
	ClearTimer(0);
	while (FastTimer(0) <= TIME_LIGHT) {// 一番明るかった場所まで回る
		OnFwd(OUT_A);
		OnRev(OUT_C);
	}
	Off(OUT_A+OUT_C)
}
  • プログラム修正
    int LIGHT_MAX=0;	//一番明るいところの値を入れる
    int TIME_LIGHT=0;//一番明るいところまで回るまで
    int RUN_TIME;//一回転する時間
    int cnt=0;//カウンター
    
    task main(){
    
    	SetSensor(SENSOR_2, SENSOR_LIGHT);
    	ClearTimer(0);
    	
    	OnFwd(OUT_A);
    	OnRev(OUT_C);
    	
    	repeat(50){
    		if(SENSOR_2 > LIGHT_MAX){
    			LIGHT_MAX = SENSOR_2;//一番明るいところの値が入る
    			TIME_LIGHT = cnt;//一番明るいところまでかかった時間が入る	
    		}
    	cnt++;
    	Wait(5);
    	}
    	OnFwd(OUT_C);
    	OnRev(OUT_A);
    	RUN_TIME = 250-(TIME_LIGHT-1)*5;//逆回転する時間
    	Wait(RUN_TIME);
    	Off(OUT_A+OUT_C);
    	
    }

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