- 追加された行はこの色です。
- 削除された行はこの色です。
[[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;
}
}
}
}
}