map() outputs -1

Hello Everybody,

I am working on a program that adjusts a throttle value based off of an accelerometer reading to keep a vehicle from giving the rider any side accelerations. The problem I am having is when I try to map the accelerometer values into values from 0-255 to use for adjusting the throttle I get an output of -1 .
This is how I setup the command

LeftThrottleAdjustment = map(ax, 0, 0.5, 0, 255);

The map function doesn't work well with float values, so what you can do is multiply ax by 10, 100 or even 1000 to give you a better range. Likewise the Low and High ranges must be changed too.

LeftThrottleAdjustment = map( int(ax*1000.0), 0, 500, 0, 255);

Or you could…

Although I’ll probabaly get beat up about this AGAIN…

Go here : https://github.com/leftCoast/Arduino/tree/master/libraries/LC_baseTools

Find the mapper.h & mapper.cpp files, add then to your sketch and…

#include "mapper.h"

mapper myMapper(0, 0.5, 0, 255);  // Gives you the mapper object.. (Works with floats)

//To map your values..
LeftThrottleAdjustment = myMapper.Map(ax);

-jim lee

I'm not really sure why everyone seems to think that map() is the only way to accomplish a job. Since you have the same lower limit for each range, a simple multiplication is all that is needed.

Paying attention to argument types would be helpful, too.