Arduino Scratch mapping example

If you want to use sensor data in your application you probably want to map the values to a different range. Below a visualisation of the formula that you can use for that. Drag the sliders to change the virtual sensor input value and the maximum value of the sensor.

Get Adobe Flash player

You can use this formula in every programming/scripting language of course. Below you can download a more complex example for Scratch4Arduino (S4A) that I use in my classes (it also includes a smoothing formula). The Arduino and Processing languages already have an implementation of this formula in the map() function. For an example see this post: Arduino Programming – Map and smooth values