Mapping input numerical ranges to other numbers in MAX

May 11, 2010 at 2:02pm

Mapping input numerical ranges to other numbers in MAX

Hi guys, I’m a bit new to javascripting so bear with me. I’m trying to create an object that will take an input with a certain range, say x =[200, 600] and mapping that range using “if else statements” onto various output ranges say y =[1, 10] and based upon this calibration direct the outputs out 10 separate outlets.


if 200< =x<=250 then y = 1
output y = 1 to an outlet 1

and so on until y = 10

or what would the equivalent of this switching code in javascript:

// these constants won’t change:
const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 600; // sensor maximum, discovered through experiment

void setup() {
// initialize serial communication:

void loop() {
// read the sensor:
int sensorReading = analogRead(0);
// map the sensor range to a range of four options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);

// do something different depending on the
// range value:
switch (range) {
case 0: // your hand is on the sensor
case 1: // your hand is close to the sensor
case 2: // your hand is a few inches from the sensor
case 3: // your hand is nowhere near the sensor


May 11, 2010 at 2:17pm

You may have good reasons to do this within a JS, but FWIW this is pretty easily done in max land. Check [split]

– Pasted Max Patch, click to expand. –
May 11, 2010 at 2:39pm

Thanks that does help a lot.

May 12, 2010 at 12:38pm

you could probably also use the regular if else max object on your data stream


You must be logged in to reply to this topic.