Using the accelerometer for sending midi data.. I really need help!

I want to use the accelerometer to make a sound effect 'slider' go up and down when it is moved..

I know that the serial.begin has to be (31250) for 'midi baud rate' so I have changed that

Now I need HELP with setting the range values to the min of '127' for each of the variables(expect tmp).

#include<Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(31250);//MIDI baud rate 
 // Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  Serial.print(" | AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);
  delay(333);
}

Now I need HELP with setting the range values to the min of '127' for each of the variables

You do not say what range of values you are receiving but if you want to change (say) 0 to 255 to 127 to 255 then have a look at the map() function.

UKHeliBob:
You do not say what range of values you are receiving but if you want to change (say) 0 to 255 to 127 to 255 then have a look at the map() function.

The highest range it can go to is 32767.

I looked at the data sheet.

Where do I (say) 0 to 255 to 127 to 255.. is it within the void loop?

Is it like this (Please look at the code below)

#include<Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(31250);//MIDI baud rate 
 // Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
 // Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)

  AcX= map(AcX, 0, 255, 127, 255);   
  AcY= map(AcY, 0, 255, 127, 255); 
  AcZ= map(AcZ, 0, 255, 127, 255); 
 // Tmp= map(Tmp, 0, 255, 127, 255); 
  GyX= map(GyX, 0, 255, 127, 255); 
  GyY= map(GyY, 0, 255, 127, 255); 
  GyZ= map(GyZ, 0, 255, 127, 255); 
  
  Serial.print(" | AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
 // Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);
  delay(333);
}

I want to set my accelerometer's range to.. 0 to 127. So while looking at the monitor and moving my sensor I only want to see the numbers from 0 to 127 nothing else.

Down below is where I have tried to use the map function in order to achieve this.. but it is not working. Please help.

#include<Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,GyX,GyY,GyZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
//  Serial.begin(31250);//MIDI baud rate 
 Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
 AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
 AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
 AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
 // Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
 GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
 GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
 GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)

  AcX= map(AcX, 0, 255, 127, 255);   
  AcY= map(AcY, 0, 255, 127, 255); 
  AcZ= map(AcZ, 0, 255, 127, 255); 
 // Tmp= map(Tmp, 0, 255, 127, 255); 
  GyX= map(GyX, 0, 255, 127, 255); 
  GyY= map(GyY, 0, 255, 127, 255); 
  GyZ= map(GyZ, 0, 255, 127, 255); 
  

  Serial.print(" | AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
 // Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);
  delay(333);
}

Down below is where I have tried to use the map function in order to achieve this.. but it is not working.

So you started ANOTHER thread? Why?

Do you get actually values between 0 and 255 on the inputs, or is that a guess based on your other thread on the same subject ? Some serial prints of the raw values would help.

but it is not working

Please describe what should happen and what actually happens.

Why did you start another thread ?

UKHeliBob:
Do you get actually values between 0 and 255 on the inputs, or is that a guess based on your other thread on the same subject ? Some serial prints of the raw values would help.
Please describe what should happen and what actually happens.

So while looking at the 'serial monitor' and moving my sensor I only want to see the numbers from 0 to 127 nothing else. 0 being the lowest and 127 being the highest..

UKHeliBob:
Why did you start another thread ?

Because I though the word 'midi' threw people off from reading it..

Do not cross-post. Threads merged.

32767 is 0x7fff
127 is 0x7f

So take your incoming value and shift it right 8 bits
byte value = incomingValue >>8;

So while looking at the 'serial monitor' and moving my sensor I only want to see the numbers from 0 to 127 nothing else. 0 being the lowest and 127 being the highest..

I was suggesting that you printed the raw values, not the mapped ones.

Read post #6. You have the output arguments wrong and probably the input arguments too.

UKHeliBob:
I was suggesting that you printed the raw values, not the mapped ones.

Read post #6. You have the output arguments wrong and probably the input arguments too.

I tried what was recommended on post 6.. that did not work either..

here is what I get without the map function ..

The video is a waste of time.
Why not post the program here together with a sample of the output ?

UKHeliBob:
The video is a waste of time.
Why not post the program here together with a sample of the output ?

The pressure sensor is working well.. the highest I can get is 127 when I put pressure on it.

The potentiometer I cant tell as it doesnt come up on the serial monitor..

the accelerometer .. AcX I am getting numbers from -13368 to 16004

AcY 12256 to -972

AcZ 16776 to -12272

GyX 2176 to 2256

GyY -6790 to 4220

GyZ -8016 to 18131

BUT THE RANGE COULD BE A LOT BIGGER OR SMALLER..

#include<Wire.h>
int note;
const int MPU_addr=0x68;  // I2C address of the MPU-6050
const int ledPin = 9;  //pin 9 has PWM funtion
const int potPin = A1; //pin A1 to read analog input
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
//Variables:
int value; //save analog value
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(9600); //(31250)
  pinMode(ledPin, OUTPUT); 
  pinMode(potPin, INPUT); //Optional 
  // Serial.begin(31250);
}
void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  Serial.print(" | AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);
  

   // Read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  
  int voltage = sensorValue / 4; // 5.0 / 1023.0
  
  voltage = min(voltage, 127);

  //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
  noteOn(0xB0, 8,voltage);
  delay(100);
  
  // Print out the value you read:
  Serial.println(voltage);
  
  // Wait 100 milliseconds
  delay(333);
  
  value = analogRead(potPin);          //Read and save analog value from potentiometer
  value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM)
  analogWrite(ledPin, value);          //Send PWM value to led
  delay(100);    
}

void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

CrossRoads:
32767 is 0x7fff
127 is 0x7f

So take your incoming value and shift it right 8 bits
byte value = incomingValue >>8;

I want to use the 'Continuous Controller' (0xB0) to control the data slider position..