# Map voltage value with two range

Hi

I don't know if i'm in the good section for my question, i apologize in advance if not.

I created a midi pedal with an expression pedal. So i convert the analog signal from analog 1 (10K pot) to midi value.

The pedal is used to control a fader of a O2R digital mixer, and i would like for example to map 0-500 (voltage) to 0 -40 (MIDI) and 501-1023 to 41-127 to be more precise and the end of the fader range. The pot is linear and it's not practical/convenient for the mix.

Is there someone who know if it possible to do something like that.

Thanks

http://playground.arduino.cc/Main/MultiMap

Is this what you seek?

I will read many times, cause i m not sure i really understand the reMap thing

Is there someone who know if it possible to do something like that.

Of course:

``````if(val < 500)
val = map(val, 0, 500, 0, 40);
else
val = map(val, 501, 1023, 41, 127);
``````

i tried that but it’s not sucessfull

there is my code

``````//#define DEBUG

const int THRESHOLD = 7;
const int PINONE =0;;
const int PINTWO =1;

void setup()
{

Serial.begin(31250); 	// Starts communication with the serial port
}

void loop(){
PedalPot0();
PedalPot1();
}

void PedalPot0 ()
{

static int LastPot0Value = 0;
static int LastMapped0Value = 0;

if(abs(CurrentPot0 - LastPot0Value) < THRESHOLD)
return;
LastPot0Value = CurrentPot0;

int Mapped0Value = map(CurrentPot0, 0, 1023, 0, 106); // Map the value to 0-127
if(Mapped0Value == LastMapped0Value)
return;
LastMapped0Value = Mapped0Value;

Serial.println(CurrentPot0);

VolumePedal0(Mapped0Value);
}

void VolumePedal0(byte volume0)
{
Serial.write(0xB0);    // Control change command
Serial.write(0x0A);                       // Volume command
Serial.write(volume0);              // Volume 0-127
}

void PedalPot1 ()
{

static int LastPot1Value = 0;
static int LastMapped1Value = 0;

if(abs(CurrentPot1 - LastPot1Value) < THRESHOLD)
return;
LastPot1Value = CurrentPot1;

int Mapped1Value = map(CurrentPot1, 0, 1023, 0, 106); // Map the value to 0-127
if(Mapped1Value == LastMapped1Value)
return;
LastMapped1Value = Mapped1Value;

VolumePedal1(Mapped1Value);
}

void VolumePedal1(byte volume1)
{
Serial.write(0xB0);    // Control change command
Serial.write(0x0C);                       // Volume command
Serial.write(volume1);              // Volume 0-127
}
``````

there is my code

Which does not do what I suggested.

i tried that but it's not sucessfull

Doesn't look to me like you tried it, but the code you posted does something. You didn't say what. You want it to do something, but you didn't say what. How can we help you, with so little info to go on?

yeah i posted my first code, but i found my error in the code you give me.

There is my new code who is working great now :

``````//#define DEBUG

const int THRESHOLD = 7;
const int PINONE =0;;
const int PINTWO =1;

void setup()
{
Serial.begin(31250);
}

void loop()
{
PedalPot0();
PedalPot1();
}

void PedalPot0 ()
{
static int LastPot0Value = 0;
static int LastMapped0Value = 0;
static int Mapped0Value = 0;

if(abs(CurrentPot0 - LastPot0Value) < THRESHOLD)
return;
LastPot0Value = CurrentPot0;

if ( CurrentPot0 < 300 )

Mapped0Value = map(CurrentPot0, 0, 250, 0, 45);

else

Mapped0Value = map(CurrentPot0, 251, 1023, 46, 106);

Mapped0Value = map(CurrentPot0, 0, 1023, 0, 106);

if(Mapped0Value == LastMapped0Value)
return;
LastMapped0Value = Mapped0Value;

VolumePedal0(Mapped0Value);
}

void VolumePedal0(byte volume0)
{
Serial.write(0xB0);    // Channel
Serial.write(0x0A);                       // Volume command
Serial.write(volume0);              // Volume
}

void PedalPot1 ()
{
static int LastPot1Value = 0;
static int LastMapped1Value = 0;
static int Mapped1Value = 0;

if(abs(CurrentPot1 - LastPot1Value) < THRESHOLD)
return;
LastPot1Value = CurrentPot1;

if ( CurrentPot1 < 300 )

Mapped1Value = map(CurrentPot1, 0, 250, 0, 45);

else

Mapped1Value = map(CurrentPot1, 251, 1023, 46, 106);

if(Mapped1Value == LastMapped1Value)
return;
LastMapped1Value = Mapped1Value;

VolumePedal1(Mapped1Value);

}

void VolumePedal1(byte volume1)
{
Serial.write(0xB0);    // Channel
Serial.write(0x0C);                       // Volume command
Serial.write(volume1);              // Volume
}
``````

Thanks