- 追加された行はこの色です。
- 削除された行はこの色です。
#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 <= 10) && (tone < 20)){
PlayTone(Do,5); Wait(10);
}else if((tone <= 20) && (tone < 30)){
PlayTone(Re,5); Wait(10);
}else if((tone <= 30) && (tone < 40)){
PlayTone(Mi,5); Wait(10);
}else if((tone <= 40) && (tone < 50)){
PlayTone(Fa,5); Wait(10);
}else if((tone <= 50) && (tone < 60)){
PlayTone(So,5); Wait(10);
}else if((tone <= 60) && (tone < 70)){
PlayTone(Ra,5); Wait(10);
}else if((tone <= 70) && (tone < 80)){
PlayTone(Si,5); Wait(10);
}else if((tone <= 80) && (tone < 90)){
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 if((SENSOR_1 >= touch) || (SENSOR_3 >= touch)){
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){
OnFwd(OUT_A+OUT_C);
}