Hi! I'm working on a lego meteorite harvester project and i'm a little confused about the IR range sensor. I attached it to the servo to get a constant scanning of area but i have no idea how to code it. After it scanned, what do i need to make it in when it detected an array of values?
#void main()
{
while(!start_button());
while(1)
{
int array[15];
int i;
printf("Testing IR range value! \n");
for(i=0;i<15;i++)
{
array= analog(5);
printf("value =%d\n",array);
}
while((!start_button())&&(!stop_button()));
if(stop_button()) break;
}
}
this is the code i make to see the value it gets.
#void main()
{
while(!start_button())
printf("Bumper test!!\n");
while(1)
{
check_distance();
while((!start_button())&&(!stop_button()));
if(stop_button()) break;
}
}
void check_distance()
{
int irval = analog(IRFinder);
//If there is wall, value approx.50-110
//if there isn't wall, value approx 0
if(irval> 50) //to be set later
{
go_straight();
}
else
{
go_back();
msleep(1000L);
turn_around();
}
}
this is the command i make whether it detects something or not.I know i am suppose to get something like "0 0 0 0 1 1 1 1 0 0 0 0" if there is something infront. if i know there's something in between, how do i make it go that direction?
I have no idea what to do with it, it would be great if someone here can help me with it! =)