Hi, I'm using the PulseIn function and obtaining a range of values (1140-1830), I'm trying to map the values from 0 to 255, but the mapped values are almost fixed en the center values, from 140-150, please take a look.
float drive=pulseIn(2, HIGH);
float drive_2=map(drive,1140,1830,0,255);
map() does a linear mapping so if most of the input values are near the center of the input range then most of the output values will be near the center of the output range. What did you expect? What did you want?
Both pulseIn() and mar() return the long or unsigned long data types. Why make them floats?
hmmm, the map function allows you to "convert" from one range of values to another, with a direct correspondence.
Something like
map(sourceValue, x, y, a, b)
so the range "from x to y" would be mapped into the range "from a to b".
When i read your message, and you say the output values of the map function are almost fixed between 140-150, it makes me think that the origin values (the range from 1140 to 1830) must also be limited to a certain smaller range, somewhere in the middle of the range.
I would suggest that you output your "drive" variable into the Serial Monitor to see what range of values it is really getting. Maybe then you can adjust the map function to work with the values you are getting on your drive variable.