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.

Visualisation removed, because Flash is now disabled on most devices. I might make a P5Js version, in the near future. Please comment if that would help you.

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

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.