Arduino Programming – Map and smooth values

Re-map a value from one range to another and smooth analog input values.

Re-map a value from one range to another and smooth analog input values.

Level : beginner with Arduino. ( Basic knowledge of programming principles like if/else and variables ).

Map.ino

Analog_smooth.ino:

  • Kenneth MacLean

    Hi there,

    I have a situation where I’d like to invert the values either side of a centre point,
    it’s an analog value ranging from 0-1000 with a centre point of 500.
    I’d like to make the analog read of 0-499 to become 499 -0 and 501-1000 to become 1000-501. This so that a lo/high threshold level will work in the opposite direction.
    I’m using a Phidget 1111 and need to control proximity, the closer you are the range is closer to the centre point and further away results in values in the extreme range. Inverting either side should make a rule better for this particular application.
    Any help would be much appreciated.
    cheers
    Kenneth

  • GodFear17

    Worked PERFECT! awesome

  • Tony

    Actually if you insert a value for the sensor read, say sensorVal = 50, then run the program rather than 50 being the average value the program returns 47. Not good enough for me.