Mapping values from an IR sensor to a servo

Hi all,

I’m not whether this would make sense asking this question here or in the robotics section, but this is more of a programing question than anything else. I’m trying to make 4 IR sensors map out different values to command a servo motor to turn certain degrees 2 of the IR sensors store a value for the left side, and 2 store a value for the right side. What I want to happen is that when the IR sensors pick something up between 25 inches and 5 inches, it turns the servo a certain amount of degrees based on how close/far an object is. I have the code for the right side working alright, but it doesn’t make sense to why it works. I’ve tried doing the left side with mixed results but none that I want. The basic code is below, full code is attached–can anyone help?

if(Prox01 <=25)
  {
    leftSide = Prox01;
    leftSide = map(leftSide, 5, 25, 130, 95);
    Steering.write(leftSide);
  }

That one works, while below does not.

  else if (Prox04 <=25)
  {
    rightSide = Prox01;
    rightSide = map(rightSide, 5, 25, 65, 95);
    Steering.write(rightSide);
  }

More information on my robot is here:

http://letsmakerobots.com/node/35388

Thanks!

So very very very close …

It can be very had to see these errors, Everything looks correct. The side you copied works but this doesn’t. That’s the clue though. Copy’n’paste error. What did you not change to make it proper for the right side ?

      else if (Prox04 <=25)
      {
        rightSide = Prox04;
        rightSide = map(rightSide, 5, 25, 65, 95);
        Steering.write(rightSide);
      }

See it now ? :mrgreen:

Prox04 is the rightSide sensor.

OHH! that’s looks like it might be a problem…Yeah…well, that wasn’t so smart of me!