[[2006a/C2/課題3左]] #hr CENTER:&size(25){光源を見失った時には曲を演奏しながらぐるっと旋回して光源を探すプログラム}; #hr RIGHT:カウンタ&counter; RIGHT:[[ロボティクス入門ゼミ]] RIGHT:[[2006a/C2/課題3左に戻る>2006a/C2/課題3左#i359fd9c]] --目次 #contents **プログラム内容 [#r4b254c3] #define timer 200 //music nomber #define Do 523 #define Re 587 #define Mi 659 #define Fa 698 #define So 784 #define Ra 880 #define Si 988 #define Do2 1047 int touch; task music(){ int tone; tone = (SENSOR_1 + SENSOR_3) / 2; while(1){ if((tone <= 20) && (tone < 23)){ PlayTone(Do,5); Wait(10); }else if((tone <= 23) && (tone < 26)){ PlayTone(Re,5); Wait(10); }else if((tone <= 26) && (tone < 29)){ PlayTone(Mi,5); Wait(10); }else if((tone <= 29) && (tone < 32)){ PlayTone(Fa,5); Wait(10); }else if((tone <= 32) && (tone < 35)){ PlayTone(So,5); Wait(10); }else if((tone <= 35) && (tone < 38)){ PlayTone(Ra,5); Wait(10); }else if((tone <= 38) && (tone < 41)){ PlayTone(Si,5); Wait(10); }else if((tone <= 41) && (tone < 44)){ PlayTone(Do2,5); Wait(10); } } } task main(){ SetSensor(SENSOR_1,SENSOR_LIGHT); SetSensor(SENSOR_3,SENSOR_LIGHT); touch = (SENSOR_1 + SENSOR_3) * 3 / 5; while(1){ if((SENSOR_1 < touch) && (SENSOR_3 < touch)){ if(SENSOR_1 > SENSOR_3){ trun_r(); }else if(SENSOR_1 < SENSOR_3){ trun_l(); } }else{ stop music; straight(); } } } void trun_r(void){ start music; OnFwd(OUT_C); OnRev(OUT_A); until((SENSOR_1 >= touch) || (SENSOR_3 >= touch)); } void trun_l(void){ start music; OnFwd(OUT_A); OnRev(OUT_C); until((SENSOR_1 >= touch) || (SENSOR_3 >= touch)); } void straight(void){ if((SENSOR_1 >= touch) && (SENSOR_3 >= touch)){ OnFwd(OUT_A+OUT_C); }else if((SENSOR_1 >= touch) && (SENSOR_3 < touch)){ OnFwd(OUT_C); OnRev(OUT_A); }else if((SENSOR_1 < touch) && (SENSOR_3 >= touch)){ OnFwd(OUT_A); OnRev(OUT_C); } } ---------- **プログラム説明 [#h47ed3dc] ---------- ***コメント・感想・アドバイス [#v90aa74b] #comment -------- RIGHT:[[ロボティクス入門ゼミ]] RIGHT:[[2006a/C2/課題3左に戻る>2006a/C2/課題3左#i359fd9c]]