Pitchbend and mode wheel

#include <MIDI.h>
// Created and binds the MIDI interface to the default hardware Serial port
MIDI_CREATE_DEFAULT_INSTANCE();

/************** EDIT HERE ****************/

// MIDI channel to send messages to
const int channelOut = 1;

// MIDI CC Number for 2nd wheel
const int CONTROLWHEEL2 = 1;

/************ END EDIT HERE **************/

int lastWheel0 = 100000;
int lastWheel1 = 100000;

const int numReadings = 30;

int wheel0Min = 1023;
int wheel1Min = 1023;

int wheel0Max = 0;
int wheel1Max = 0;

boolean cMode = false;

int wheel0Raw = 0;
int wheel1Raw = 0;

int idx=0;
int readings0[numReadings];
int readings1[numReadings];

int wheel0Total = 0;
int wheel1Total = 0;

int wheel0Avg = 0;
int wheel1Avg = 0;

boolean FIRSTRUN = true;
static boolean test=false;

int WHEEL1 = A0;
int WHEEL2 = A1;

void setup() {
if(test==false){
MIDI.begin(1);
MIDI.turnThruOff();
}
pinMode(8, INPUT);
pinMode(13, OUTPUT);
if(test==true){
Serial.begin(9600);
}
readings0[0]=0;
readings1[0]=0;

//calibrate!

}

void calibrate_wheels(){
wheel0Raw = analogRead(WHEEL1);
wheel1Raw = analogRead(WHEEL2);

// record the maximum sensor value
if (wheel0Raw > wheel0Max) {
  wheel0Max = wheel0Raw;
}

if (wheel1Raw > wheel1Max){
    wheel1Max = wheel1Raw;
}



// record the minimum sensor value
if (wheel0Raw < wheel0Min) {
  wheel0Min = wheel0Raw;
}
if (wheel1Raw < wheel1Min) {
  wheel1Min = wheel1Raw;
} 


} 

void loop() {

int calibrate = digitalRead(8);

if(calibrate==HIGH){
if(cMode==false){
cMode=true;
wheel0Min = 1500;
wheel1Min = 1500;
wheel0Max = 0;
wheel1Max = 0;

}

 digitalWrite(13, HIGH);
 calibrate_wheels(); 

 return;

}else{
digitalWrite(13, LOW);
cMode=false;
}

// average the readings!
wheel0Total = wheel0Total - readings0[idx];
wheel1Total = wheel1Total - readings1[idx];

readings0[idx] = analogRead(WHEEL1);
readings1[idx] = analogRead(WHEEL2);

if(test==true){
Serial.println(readings0[idx]);
}
wheel0Total = wheel0Total + readings0[idx];
wheel1Total = wheel1Total + readings1[idx];

idx = idx + 1;

if(idx >= numReadings){
idx=0;
}

wheel0Avg = wheel0Total / numReadings;
wheel1Avg = wheel1Total / numReadings;

// Process Mod cc
if(wheel0Avg<wheel0Min){
wheel0Avg=wheel0Min;
}

if(wheel0Avg>wheel0Max){
wheel0Avg=wheel0Max;
}
int mappedWheel0 = map(wheel0Avg, wheel0Min, wheel0Max, -8192, 8191);

if(mappedWheel0>8000) mappedWheel0 = 8191;
if(mappedWheel0<-7500) mappedWheel0 = -8192;

if(mappedWheel0<1200&&mappedWheel0>-200){
 mappedWheel0=0; 
}

if(mappedWheel0>lastWheel0+150||mappedWheel0<lastWheel0-150){

  lastWheel0 = mappedWheel0;
  
   //Serial.println(mappedWheel0);
if(test==false){
  MIDI.sendPitchBend(mappedWheel0, channelOut);
}
  //Serial.println(mappedWheel0);
}else{
  
}

// Process Volume cc

int mappedWheel1 = map(wheel1Avg, wheel1Min, wheel1Max, 0, 127); //map value to 0-127

if(mappedWheel1>124) mappedWheel1 = 127;
if(mappedWheel1<5) mappedWheel1 = 0;

if(mappedWheel1>lastWheel1+2||mappedWheel1<lastWheel1-2){
  lastWheel1=mappedWheel1;
  //
    if(test==false){
      MIDI.sendControlChange(CONTROLWHEEL2, mappedWheel1, channelOut);
    }
 // digitalWrite(13, HIGH);      
}else{

}

}

i have problem in pitch bend it is not giving any midi signal, anybody please help

/Users/john/Documents/Arduino/sketch_apr27a/sketch_apr27a.ino:15:18: warning: overflow in implicit constant conversion [-Woverflow]
 int lastWheel0 = 100000;
                  ^~~~~~
/Users/john/Documents/Arduino/sketch_apr27a/sketch_apr27a.ino:16:18: warning: overflow in implicit constant conversion [-Woverflow]
 int lastWheel1 = 100000;
                  ^~~~~~

It's saying "I can convert your 100000 to a 'long int' constant (100000L) because you can't fit it into an 'int' but then you store it in an 'int' so the value is going to get truncated to 16 bits."

100,000 is hex 186A0 which gets truncated to 86A0 which, in an 'int', is -31072. The largest number that will fit in a signed 16-bit integer is 32767.

Hi
Thanks for the mail
I am very new to this field !
I wrote this code without any knowledge
Actually I got this code and it was not working well (showed pan,mod and volume in one Analoge port and sometimes pitch bend too) I have deleted some pots from the code and made this one
I really need help to correct it I don’t know how and what to do
When I compiled I have got this overflow msg !
What change I should make in this code !?
Thanks a lot
Ajiesh Anto

Replace 100000 with a number that will fit. The largest number that will fit in a signed 16-bit integer is 32767.

Thanks
Will try that

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