// Program for Dude, Where's my Bot?
void main() {
wait_for_light(2);
shut_down_in(89.);
fd(A);
fd(C);
sleep(6.);
bk(A);
bk(C);
sleep(1.);
fd(A);
fd(C);
sleep(2.);
bk(A);
bk(C);
sleep(1.);
fd(A);
fd(C);
sleep(4.5);
fd(A);
bk(C);
}
void wait_for_light(int light_port_)
{
int l_on_, l_off_, l_mid_, l_diff_, t;
/* print statements may look funny but are spaced for LCD*/
printf ("DWMB", light_port_);
sleep(2.);
printf("On V");
while(!view_button());
l_on_=light_passive(light_port_); /*sensor value when light is on*/
beep();
printf("On%d", l_on_);
sleep(1.);
beep();
printf("Off P");
while(!prgm_button());
l_off_=light_passive(light_port_); /*sensor value when light is off*/
beep();
printf("Of%d", l_off_);
sleep(1.);
beep();
if((l_off_-l_on_)>=15){ /*bright = small values */
l_mid_=(l_on_+l_off_)/2;
l_diff_=(l_off_-l_on_);
printf("Good",l_diff_);
while(light_passive(light_port_)>l_mid_){
tone(440.,0.4);
printf("good");
if(light_passive(light_port_)>l_mid_)tone(440.,0.4);
printf("D=%d",l_diff_);
}
}
else{
if(l_off_<450){
printf("Bad");
while(1) /*never terminate */
for(t=100; t<10000; t=t+1200) {
printf("Bad");
tone((float)t,0.5);
printf("ADD");
tone((float)(400+t),0.5);
printf("Shield");
tone((float)(800+t),0.5);
}
}
else{
printf("Bad Calibration Aim sensor!!\n");
while(1) /*never terminate */
for(t=10000; t>200; t=t-1200) {
printf("Bad");
tone((float)t,0.5);
printf("point");
tone((float)(t-400),0.5);
printf("Sensor");
tone((float)(t-800),0.5);
}
}
}
}
//
// Function: shut_down_in(float: delay)
//
// This function will start a background process which sleeps for "delay",
// then stops the motors and kills all other processes.
//
// This function cannot work if another process continually calls
// "hog_processor", since the background task will never gain control.
//
// This function may not work if more than 1000 processes have been
// created between the original call to "shut_down_in" and when the delay
// is finished.
//
int _shut_down_pid;
float _shut_down_delay;
int Bb_Game_Over;
void shut_down_in(float delay)
{
Bb_Game_Over= 0;
printf("sd %d", (int)delay);
// Passing delay to shut_down_task crashes the RCX
_shut_down_delay= delay;
_shut_down_pid= start_process(_shut_down_task());
}
void _shut_down_task()
{
int i,j;
sleep(_shut_down_delay);
hog_processor();
ao();
Bb_Game_Over= 1;
printf("Done");
i= 0;
for (j= 128; j <= 1024; j+=128) {
hog_processor();
ao();
while (i < j) {
if (++i+_shut_down_pid) kill_process(i+_shut_down_pid);
if (_shut_down_pid-i) kill_process(_shut_down_pid-i);
}
}
printf("Done.");
}