# syntax for fscale code

In reference to this code that changes the curve or scale of numbers:
http://playground.arduino.cc/main/fscale

I have this code that give my the desired curve on a reading that is from 1 to 64, but I can’t figure out how to get the same result for the values -1 to -64

``````  if (motor_speed > 0)  motor_speed = fscale( 1, 64, 1, 64, motor_speed, -1.5);
``````

I thought this would do it, but all it gives me is zeros:

``````  if (motor_speed < 0)  motor_speed = fscale( -1, -64, -1, -64, motor_speed, -1.5);
``````

The motor still has a speed, yes? I'm no math whiz, and I don't know what circuit you're using, but can't you just negate the value(s) returned from the function? In other words, feed it athe abs(motor_speed), then negate the reult and fee it to motor_speed.

If I'm actually way off, I beg your indulgence.

-1 to -64 is the reverse speed...

I haven't tested that function but it appears to have explicit support for negative ranges. Have you got a sample sketch we could run showing the incorrect values when you try to apply it to a negative range?

If you can't be bothered figuring out what the problem is, you could just negate the input motor_speed if it was negative, and then invert the result too.

I think I got it:

``````  if (motor_speed < 0)  motor_speed = fscale( -1, -64, -1, -64, motor_speed, -1.5);
``````

This doesn’t fit the rules:
originalMin - the minimum value of the original range - this MUST be less than origninalMax
originalMax - the maximum value of the original range - this MUST be greater than orginalMin

-1 isn’t lower than -64

SouthernAtHeart: -1 to -64 is the reverse speed...

Yes, of course, but a value of, lets say, -10 is just the same speed as +10, but in the opposite direction, no? If you want to increase the reverse speed, you send it a more negative number, right? It would be worth a shot to try it. Just make all the values you pass the same as you would pass if it was a forward speed. Negate the result and set the speed. See if it works. It's what I would try right away, partly because it makes sense, and partly because it's dead easy to try.

SouthernAtHeart:
In reference to this code that changes the curve or scale of numbers:
http://playground.arduino.cc/main/fscale

I have this code that give my the desired curve on a reading that is from 1 to 64, but I can’t figure out how to get the same result for the values -1 to -64

``````  if (motor_speed > 0)  motor_speed = fscale( 1, 64, 1, 64, motor_speed, -1.5);
``````

I thought this would do it, but all it gives me is zeros:

``````  if (motor_speed < 0)  motor_speed = fscale( -1, -64, -1, -64, motor_speed, -1.5);
``````

use the positive working variation?

``````  if (motor_speed < 0)  motor_speed = -fscale( 1, 64, 1, 64, -motor_speed, -1.5);
``````