Arduino servo reverse?

So i have 5 servos and 5 flex sensors. originally i had all the servos facing the same way, but now i have some upside down and some the same. I am guessing you change this in the map function to reverse the upside down ones. this is the map functions i have currently:

   byte servoVal1 = map(FingerV1,0, 500, 0, 255);
   byte servoVal2 = map(FingerV2,0, 500, 0, 255);
   byte servoVal3 = map(FingerV3,0, 500, 0, 255);
   byte servoVal4 = map(FingerV4,0, 500, 0, 255);
   byte servoVal5 = map(FingerV5,0, 500, 0, 255);

So i you help me change this so they are reverse that would be great. i have tried for a couple hours now with different values but they are still not doing what i want them to.

Thanks

You need to change on of the ranges:

byte servoVal1 = map(FingerV1,0, 500, 0, 255); // goes one way
byte servoVal1 = map(FingerV1,0, 500, 255, 0); // goes the other

Keep in mind that most servos can't rotate to 255 degrees, so the to range probably should involve 0 and 179.

See well heres the wierd thing i have them all to this:

   byte servoVal1 = map(FingerV1,0, 500, 0, 255);
   byte servoVal2 = map(FingerV2,0, 500, 0, 255);
   byte servoVal3 = map(FingerV3,0, 500, 0, 255);
   byte servoVal4 = map(FingerV4,0, 500, 0, 255);
   byte servoVal5 = map(FingerV5,0, 500, 0, 255);

And this works but its the opposite of what i want. so i changed it to this:

   byte servoVal1 = map(FingerV1,0, 500, 255, 0);
   byte servoVal2 = map(FingerV2,0, 500, 255, 0);
   byte servoVal3 = map(FingerV3,0, 500, 255, 0);
   byte servoVal4 = map(FingerV4,0, 500, 255, 0);
   byte servoVal5 = map(FingerV5,0, 500, 255, 0);

And with this the servos turn maybe 45degrees or less. Whats going on?

If you are going to use the servo library with servo positions 0-180 (n), then the reversed servo position probably could be generated using something like nr = (180 - n).

Whats going on?

You’re the one with the hardware…

Add some Serial.print() statements, to print out FingerV1 and servoVal1 for each way of defining map ranges. It should be fairly obvious what the issue is.

You haven’t said anything about the servos - what there rotational capabilities are - so it’s hard to be more specific. In general, though, servo.write() expects values between 0 and 179, since that is the range of typical servos.

The servos have 200 degrees of motion. and i should do this:

Serial.print(servoVal1);
   Serial.print(servoVal2);
   Serial.print(servoVal3);
   Serial.print(servoVal4);
   Serial.print(servoVal5);
   Serial.print(FingerV1);
   Serial.print(FingerV2);
   Serial.print(FingerV3);
   Serial.print(FingerV4);
   Serial.print(FingerV5);

But on the receiving code what should FingerV1=?

Since all the code looks identical, it is really only necessary to print one pair of values. Each value should have some meaningful description in front of it.

Serial.print("FingerV1: "); Serial.println(FingerV1);
Serial.print("servoBal1: "); Serial.println(servoVal1);

But on the receiving code what should FingerV1=?

The "receiving code" should be the Serial Monitor. Finger1 should be an integer in the range 0 to 1023.

The servos have 200 degrees of motion

Then why is the upper limit of the to range 255? The lower limit and upper limit of the to range should match the range that the servo can actually move to.

The lower and upper limit of the from range should also correspond to the range of values that the sensor can return. Typically, this would be 0 to 1023. But, if the sensor is part of a voltage divider, or for other reasons can never return values less than, or greater than, some value, it is OK to use the experimentally derived limits for the from range.

Alright well please if you know how to fix this just please tell me because I have to present this tommarow and I’m a good amount from being done. So if you see somthing that’s wrong with it just please me so I can get it working

Reply #3?