Send midi control change

Hi everybody

I’m new here i try to send a CC message and nothing happens

#include <MIDI.h>


MIDI_CREATE_DEFAULT_INSTANCE();
// read potentiometer value
//int analogValue = 0;
// maximum MIDI value is 127, first/previous potentiometer
// move has to always be different than previous value
int AnalogValue = 0; // define variables for the controller data
int lastAnalogValue = 128;
void setup()
{
   Serial.begin(31250);
    MIDI.begin (MIDI_CHANNEL_OMNI);                      // Launch MIDI and listen to channel omni
}

void loop()
{
   
        // Analog potentiometer
  
  // potentiometer gives values up to 1023
  // we need values not bigger than 127 
  int analogValue = analogRead(A0)/8;
  
  // potentiometer could be too sensitive and
  // give different (+-1) values.
  // send CC only when the difference between last value
  // is more than 1 
  if ((analogValue-lastAnalogValue) > 1 || (analogValue-lastAnalogValue) < -1) 
  
  {
    // value changed?
    if (analogValue != lastAnalogValue) {
      // send serial value (ControlNumber 1, ControlValue = analogValue, Channel 1)
      // more info: http://arduinomidilib.sourceforge.net/a00001.html
      MIDI.sendControlChange(12, analogValue, 1);
      lastAnalogValue = analogValue;
    }
     }
      }

MIDI-OX moves when i touch the pot but no CC sent…

Thanks

Get rid of the int because this creates a new variable that is not the same as the global variable of the same name.

Also replace

if ((analogValue-lastAnalogValue) > 1 || (analogValue-lastAnalogValue) < -1)
with

if ( abs (analogValue-lastAnalogValue) > 2)

Also no need for this

 if (analogValue != lastAnalogValue) 

Because this is already true when you get to this point.

Thanks for reply i tried without success.
But this is strange i also tried this

#include <MIDI.h>


MIDI_CREATE_DEFAULT_INSTANCE();



void setup() 
{
   Serial.begin(31250);
    MIDI.begin (MIDI_CHANNEL_OMNI);                      // Launch MIDI and listen to channel omni
}


void loop() {
  // put your main code here, to run repeatedly:
 MIDI.sendControlChange(12, 10, 1);
}

and only clock is send, no CC

Well that is not what I asked you to do. However this code is based on what you posted last. I have tested it and it works.

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

void setup() 
{
    Serial.begin(31250);
    MIDI.begin(1);
    MIDI.turnThruOff();
}

void loop() {
 MIDI.sendControlChange(12,   10,      1);
 //                    CC   value  channel
 delay(1000); // don't send too fast
}

OK thanks

This code doesn’t send CC i think my shield is not good that’s why i can try many codes and nothing works

It could be your lead as well.

What shield are you using?

I use this MIDI shield
with this arduino uno
I connect Tx, Rx, 5V and GND

Thanks a lot for your help

Do i have to buy another one?

What did you connect additionaly? When you plug the shield on the Arduino, all connections are done.

nothing only these four pins

Did you not directly plug it on the UNO? Why?

There was no plug that’s why i connected only 4
Is it right or i hate to connect everything?

i buied a new shield and everything is good thanks for your help

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