We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello, beautiful people.
I'm working with an ultrasonic proximity sensor from which I get values that range from 0 to 200, and are directly proportional to the distance the object measured by the sensor is from it, in centimeters. if an object touches the sensor, the value measured is 0.
I would like to invert this connection: instead of a directly proportional input, an inversely proportional one, from which I get bigger values the closer the object is to the sensor. how could I achieve this?
Answers
Question: 200 is in actual distance units? If 200 is the max value then you could do
So if the object is close to the sensor, let's say at zero, invPropValue will be 200.
Kf
I think you meant
Anyway, that worked for me!! Thank you :bz
My mistake. You are right!
Kf
Or, to hardcode it:
map()
is flexible in the general case, but a bit overkill for a zero-max inversion -- at least, overkill if performance is an issue. Just subtract and you are done.