# Shifting and Scaling

So what happens when your sensor is giving your a range of numbers that just isn't big enough? Or what happens if your sensor is giving you a range of numbers that is too big? Well, what you need is a way to shift and scale your range of numbers.

EXAMPLE 1: Under optimal conditions, sensors usually have a large range of numbers that they can output. On the Cricket, for example, this range is 0 - 255. But say that my sensor is giving me values that range between 10 and 88. This might happen to a light sensor that is in a room that never gets completely dark (a 10 value perhaps) and never gets completely light (an 88 value perhaps). Say that I want and ouput range that is 0 - 100 (perhaps those represent the notes that I want to play on a Cricket). Here's how you do it:

1. Please gather the following numbers (you may need to experiment by hooking up a display module to determine these numbers)
1. __Input minimum__ (What is the lowest number your sensor is giving you?)
2. __Input maximum__ (What is the largest number your sensor is giving you?)
3. __Output minimum__ (What is the lowest number you want your sensor to give you?)
4. __Output maximum__ (What is the largest number you want your sensor to give you?)
2. Evaluate the shifting and scaling equation.
1. Scaled_Input = (Input_Value - Input_Min) * (Output_Max - Output_Min) / (Input_Max - Input_Min) + Ouput_Min
2. For Example 1 we would do the following ...
 Scaled_Input = (Input - 10) * (100 - 0) / (88 - 10) + 0 Scaled_Input = (Input - 10) * (100 / 78) Scaled_Input = (Input - 10) * (1.28)

So, if you want to scale a value you first need to subtract 10 and then multiply it by 1.28.

You may find this page useful for more information. It is aimed at users of Lingo (another artistic programming language), but the math and graphics are useful.

## October 7, 2009

### Arduino related books

If you would like a tangible, handheld guide to the arduino there are a couple of books that you can purchase:

and

## October 1, 2009

### connecting a 12V relay to the Arduino

Connecting_a_12V_Relay_to_Arduino.pdf

You can watch this animation of a relay to get a sense of how it works.

The use of a diode with a relay is detailed here as well.

## September 10, 2009

### arduino

this is the arduino home where you can find resources to connect you with:

parts of the arduino board

software

getting started

learning tips and tutorials