Pressure sensor & potentiometer code for sending 'MIDI Control Change Messages'

I want to use these two components to send MIDI CC data.. can you look at my code below and see what I have done wrong.. I am not getting any errors but it isn't doing what it is suppose to.

int note1;
int note2;

void setup()
{
  //  Set MIDI baud rate:
  Serial.begin(31250);
}

void loop()
{
  // Read the input on analog pin 0:
  int PressSensorValue = analogRead(A0);
  int PotSensorValue = analogRead(A1);

  int PressReadings = PressSensorValue / 8;
  int PotReadings = PotSensorValue / 8; 

  PressReadings = min(PressReadings, 127);
  PotReadings = min(PotReadings, 127);

 
  noteOn(0xB0, 8, PressReadings);
  delay(100);

 
  noteOn(0xB0, 88, PotReadings);
  delay(100);

  Serial.println(PotReadings);

  Serial.println(PressReadings);


  delay(3333);

}

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

What is it supposed to do?

You are sending the midi messages to the same Serial port as the debugging Serial.println. Is that what you want to do?

Pete

el_supremo:
What is it supposed to do?

You are sending the midi messages to the same Serial port as the debugging Serial.println. Is that what you want to do?

Pete

No I am not.. do I need to make a separate port?

Also by 'serial port' do you mean

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

do I need to make a separate port?

Yes

Also by 'serial port' do you mean

Yes and also

Serial.println(PressReadings);

is using the same port.

Grumpy_Mike:
Yes
Yes and also

Serial.println(PressReadings);

is using the same port.

Is this better now?

int note1;
int note2;

void setup()
{
  //  Set MIDI baud rate:
  Serial.begin(31250);
}

void loop()
{
  // Read the input on analog pin 0:
  int PressSensorValue = analogRead(A0);
  int PotSensorValue = analogRead(A1);

  int PressReadings = PressSensorValue / 8;
  int PotReadings = PotSensorValue / 8;

  PressReadings = min(PressReadings, 127);
  PotReadings = min(PotReadings, 127);


  noteOnPress(0xB0, 8, PressReadings);
  delay(100);


  noteOnPot(0xB0, 88, PotReadings);
  delay(100);

  Serial.println(PotReadings);

  Serial.println(PressReadings);


  delay(3333);

}

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

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

Is this better now?

No you are still using the same serial port for MIDI and debugging printing.

Grumpy_Mike:
No you are still using the same serial port for MIDI and debugging printing.

I am so confused.. What am I suppose to change sir?

It seems like you don't understand what is going on. The serial port is sending your MIDI data and is sending debugging print information.

The simplest thing to do is to remove all debug printing.

If you want debug printing as well as MIDI then on a Uno then you have to make a instance of software serial, then connect the pins you chose with a USB to TTL cable and attach that to your computer and use an external serial monitor like "putty" or one of the many others. Your software serial should be set at a standard baud rate and not the MIDI baud rate, and your terminal program should be set to match this baud rate.

Grumpy_Mike:
It seems like you don't understand what is going on. The serial port is sending your MIDI data and is sending debugging print information.

The simplest thing to do is to remove all debug printing.

If you want debug printing as well as MIDI then on a Uno then you have to make a instance of software serial, then connect the pins you chose with a USB to TTL cable and attach that to your computer and use an external serial monitor like "putty" or one of the many others. Your software serial should be set at a standard baud rate and not the MIDI baud rate, and your terminal program should be set to match this baud rate.

I have removed the 'Serial.println'

What have i got to change next?

I want to send CC messages to 'CC' number 8 and 88.

int note1;
int note2;

void setup()
{
  //  Set MIDI baud rate:
  Serial.begin(31250);
}

void loop()
{
  // Read the input on analog pin 0:
  int PressSensorValue = analogRead(A0);
  int PotSensorValue = analogRead(A1);

  int PressReadings = PressSensorValue / 8;
  int PotReadings = PotSensorValue / 8;

  PressReadings = min(PressReadings, 127);
  PotReadings = min(PotReadings, 127);


  noteOnPress(0xB0, 8, PressReadings);
  delay(100);


  noteOnPot(0xB0, 88, PotReadings);
  delay(100);


  delay(3333);

}

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

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

Does it not work now? What is your hardware setup like?

Grumpy_Mike:
Does it not work now? What is your hardware setup like?

I have the Pressure sensor & potentiometer set up..

and I also have the 5 pin midi socket set up too with a 'in' cable plugged into it from the 'usb to midi' adapter..

You think my code is well written enough to carry on with the process?

There is a lot wrong with that code but it should produce something at the MIDI output.

Remove the calls to the MIDI output, and disconnect the MIDI plug. Then set your baud rate to a standard one and out your debug print statements back. Do you see any sensible output on the serial monitor?

Grumpy_Mike:
There is a lot wrong with that code but it should produce something at the MIDI output.

Remove the calls to the MIDI output, and disconnect the MIDI plug. Then set your baud rate to a standard one and out your debug print statements back. Do you see any sensible output on the serial monitor?

I changed the code to what you said..

This is the result..

int note1;
int note2;

void setup()
{

  Serial.begin(9600);  //(31250)
}

void loop()
{
  // Read the input on analog pin 0:
  int PressSensorValue = analogRead(A0);
  int PotSensorValue = analogRead(A1);

  int PressReadings = PressSensorValue / 4;
  int PotReadings = PotSensorValue / 8; 

  PressReadings = min(PressReadings, 127);
  PotReadings = min(PotReadings, 127);

 
  noteOnPress(0xB0, 8, PressReadings);
  delay(100);

 
  noteOnPot(0xB0, 88, PotReadings);
  delay(100);

  Serial.println(PotReadings);

  Serial.println(PressReadings);


  delay(333);

}

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

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

I changed the code to what you said.

No you didn't. I said:-

Remove the calls to the MIDI output, and disconnect the MIDI plug. Then set your baud rate to a standard one and out your debug print statements back.

You have not
Remove the calls to the MIDI output
and you have not
put your debug print statements back

@Benny_Leonard: How do you know that it is not working? Which device receives the midi messages and what does it do with them?

This is beginning to smell like an X/Y problem.

Pete