midi pitch bend resolution

Hi,
I'm using this code to send midi pitchbend data to "hairless serial to midi" converter:

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

void loop() {
  int sensorValue = analogRead(A0);
  sensorValue=map(sensorValue, 0, 1023, 0, 127);
  Serial.write(225);
  Serial.write(sensorValue);
  Serial.write(sensorValue);
 

}

the code is working but im only get a resolution of 128 steps.
pitchbend resolution is 16,384 steps.
I've red somewhere that i need to use both two last bits together in order to get 14 bit resolution.
How do i implant it in this code?
Thanks

See MIDI Pitch Bend | Sound Examples

Steve

How do you expect to get 14-bit resolution from a 10-bit A/D reading??

RayLivingston:
How do you expect to get 14-bit resolution from a 10-bit A/D reading??

You can't get 14-bit resolution but what you can get is 10-bit resolution mapped to a 14-bit RANGE. Considerably better than 10-bit mapped to 7-bit.

Steve

Map to a 14-bit value and split that into two 7-bit values:

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


void loop()
{
  int sensorValue = analogRead(A0);
  sensorValue = map(sensorValue, 0, 1023, 0, 0x3FFF); // 14 bits
  Serial.write(225);
  Serial.write(sensorValue & 0x7F); // Low 7 bits
  Serial.write((sensorValue >> 7) & 0x7F); // High 7 bits
}

Which gives you a non-linear response. It will count 0-7, the skip to 256-263, then skip to 512-519...

The only sensible thing to do is remove the map statement, take the A/D value and shift it left 4 places.

RayLivingston:
Which gives you a non-linear response. It will count 0-7, the skip to 256-263, then skip to 512-519...

???

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.