0% found this document useful (0 votes)
2 views

Include

The document contains multiple C code snippets for controlling a robotic system using infrared (IR) detection, microphone input, and photo sensors. Each code section implements different behaviors such as moving forward, turning, and stopping based on sensor readings. The main functions include responding to IR signals, detecting sound levels, and adjusting motor actions accordingly.

Uploaded by

guangyaoyanwang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Include

The document contains multiple C code snippets for controlling a robotic system using infrared (IR) detection, microphone input, and photo sensors. Each code section implements different behaviors such as moving forward, turning, and stopping based on sensor readings. The main functions include responding to IR signals, detecting sound levels, and adjusting motor actions accordingly.

Uploaded by

guangyaoyanwang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include "AS_UIII_LIB.

h"
int ir_1=0;
void main()
{int i;
int ir_1=0;
int flag=1;

while(!ir_detector());
while(1){
if(ir_detector()==1||ir_detector()==4||ir_detector()==2)
{motor( 1 , 30 );//直行 1m
motor( 2 , 30 );
wait( 2.500000 );

drive( 0 ,-50);//左转 0.5


wait( 0.2 );
stop();
motor( 1 , 30 );
motor( 2 , 30 );
wait(2.500000 );

drive( 0 ,30);//右转 0.5


wait( 0.2 );
stop();
motor( 1 , 30 );
motor( 2 , 30 );
wait( 2.500000 );

drive( 0 ,30);//右转 0.5


wait( 0.2);
stop();
motor( 1 , 30 );
motor( 2 , 30 );
wait( 2.500000 );

drive( 0 ,30);//右转
wait( 0.2 );
stop();
motor( 1 , 30 );
motor( 2 , 30 );
wait( 3.500000 );直行 1.5m
stop();}}
}
#include "AS_UIII_LIB.h"
int s[100];
void main()
{
int i;
Beep();
for(i=0;i<40;++i)
{
switch(ir_detector())
{
case 0:s[i]=0;stop();break;
case 1:s[i]=1;motor(1,25);motor(2,12);break;
case 2:s[i]=2;motor(1,12);motor(2,25);break;
case 4:s[i]=4;motor(1,25);motor(2,25);break;
}
wait(0.3);
if(microphone()>400)
{
s[i+1]=5;
break;
}
}
stop();
Beep();
wait(3.0);
while(microphone()<400);
Beep();
for(i=0;i<40&&s[i]!=5;++i)
{

switch(s[i])
{
case 0:stop();break;
case 1:motor(1,25);motor(2,12);break;
case 2:motor(1,12);motor(2,25);break;
case 4:motor(1,25);motor(2,25);break;
}
tone(440.0,0.15);tone(523.2,0.1);tone(523.2,0.1);
}
stop();
Beep();

}
#include "AS_UIII_LIB.h"
int photo_1=0;
int bmp_1=0;
int mic_1=0;
int ir_1=0;
void main()
{
/**/
int mic_1=0;
while(1)
{
mic_1 = microphone();
if( mic_1 > 300)
{
motor(1,30);motor(2,30);wait(1.5); // 直行
drive( 0 ,37); //120
wait( 0.26);
stop();
motor( 1 , 30 );
motor( 2 , 30 );
wait(1.500000 );

drive( 0 ,37); //120


wait( 0.26);
stop();
motor( 1 , 30 );
motor( 2 , 30 );
wait(1.500000 );
break;
}
}
while(1)
{
photo_1 = photo(1);

if(photo_1 < 300)


{
wait( 0.500000 );
drive( 0 ,15);
wait( 0.500000 );
stop();
wait( 0.500000 );
}
photo_1 = photo(2);

if(photo_1 < 300)


{
wait( 0.500000 );
drive( 0 ,-15);
wait( 0.500000 );
stop();
wait( 0.500000 );
}
else
{
wait( 0.500000 );
motor( 1 , 30 );
motor( 2 , 30 );
wait( 0.500000 );
stop();
}
bmp_1 = bumper();
ir_1=ir_detector();
if( bmp_1 == 3||ir_1==4||ir_1==1||ir_1==2)
{
stop();
break;
}
}
wait(2.0);
while(1)
{
mic_1 = microphone();
if( mic_1 > 300)
{
motor(1,-30);motor(2,-30);wait(1.5); // 直行

drive( 0 ,-37); //120


wait( 0.26);
stop();
motor( 1 , -30 );
motor( 2 , -30 );
wait(1.500000 );

drive( 0 ,-37); //120


wait( 0.26);
stop();
motor( 1 , -30 );
motor( 2 , -30 );
wait(1.500000 );
break;
}
}

while(1)
{
photo_1 = photo(1);

if(photo_1 < 300)


{
wait( 0.500000 );
drive( 0 ,15);
wait( 0.500000 );

You might also like