Author Topic: Help regarding IR sensor  (Read 469 times)

0 Members and 1 Guest are viewing this topic.

Offline ChocotwilightTopic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Help regarding IR sensor
« on: October 11, 2012, 09:45:22 PM »
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 but when i test the value it just give me something like "39 39 39 39 39 39 39 39 39".

I have no idea what to do with it, it would be great if someone here can help me with it! =)
« Last Edit: October 11, 2012, 09:50:18 PM by Chocotwilight »

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Help regarding IR sensor
« Reply #1 on: October 11, 2012, 11:00:22 PM »
Hi,

I have no idea what to do with it, it would be great if someone here can help me with it! =)
Software questions belong in the forum marked "Software" (surprise ;)) and please put the source code in code-tags (the button with the hash sign "#" above the text field where you write the message).
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

 


Get Your Ad Here