Unit 1A: Basic Circuits
Objective:
Learn how to use linear scaling to map data from sensors to computational control (of actuation, of sound synthesis, etc.)
We can use linear scaling to change the range of a data stream (i.e. the smallest value to the largest value), to a new desired range (e.g. between 30 degrees and 60 degrees of rotation of a servo). In mathematical terms, if x is within the range [A,B], and we want to linearly scale it to the range [C,D], we follow:
[latex] f(x)=C\left(1-\frac{x-A}{B-A}\right)+D\left(\frac{x-A}{B-A}\right) = C + (D-C)\dfrac{x-A}{B-A}[/latex]
The function is commonly used in the arduino environment ("map"), in PureData (look for the abstraction "pc.scale" and its associated help file in our repository).
Steps and observations
- This example uses the "pc.scale" abstraction to perform linear scaling. Move the slider marked "input" and see the resultant range change in the "output" slider; change the "output min" and "output max" values to see the result in range changes. The four arguments to the "pc.scale" object are [input range min, input range max, output range min, output range max]
- This example uses a "table" object to do map a stream of numbers from an input range, to a different output range. The "table" object functions as a look-up-table where the x-axis (or index) is the input value and the y-axis (or value) is the output range. Draw new values into the table and move the input slider to see changes in the mapping.
- This example uses an "array" object for the same purpose. The object offers a visual interface in the patch, and you can draw values direclty in the patch. The array's Properties allow you to set the range of values and the number of elements. Since the input slide has a size of 128, we select the same for the array. Draw new values into the array and move the input slider, to see changes in the mapping ranges.
Comments and Challenges
- Use the above techniques to map values from a simple 1-dimensional sensor (like a light sensor) to the movements of a servo
- use tables or arrays to compose a particular gesture for the movement of the servo, using data in the array/table
Other Files
- one-to-one-mapping.pd