Problem Sending MIDI CC using arrays

Newbie here..

The kind Grumpy_Mike made me a simple but effective sketch sending MIDI programchange to a PC using an arduino pro micro. I modified it slightly according to my needs and it worked beyond my wildest dreams! ( Been using a simple but working sketch before that but it was buggy).

Now I'm trying to modify it further by making it send controlChange instead but I always get this error (see attached image. It seems i dont have an idea of the controlChange parameter needed.

In this part of the code, it seem simple enough for programChane but simple substitution didn't work for the controlChange part (I have no prior programming training; just sort of curiosity and eagerness to learn new things type of education :slight_smile: )

void programChange(byte channel, byte patch) {
  midiEventPacket_t event = {0x0C, 0xC0 | channel, patch};
  MidiUSB.sendMIDI(event);
   MidiUSB.flush();
}
   
void  controlChange(byte channel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
  MidiUSB.sendMIDI(event);
  MidiUSB.flush();

Thank you so much for any help.

here is the full code

// Simple MIDI output of program message through USB
// By Grumpy_Mike August 2019

#include <MIDIUSB.h>

// to add more then simply add more pins tothe list
byte ledPin[] = {A0,A1,A2,A3,A6,A7,A8,A9,A10};  // list of led pins
byte buttonPin[] = {0,1,2,3,5,7,15,14,16};    // list of buttons pins
byte buttonState[] = {0,0,0,0,0,0,0,0,0};  // start off with off
byte lastButtonState[] = {0,0,0,0,0,0,0,0,0};  // start off with off
//byte programChanges[] = {0,1,2,3,4,5,6,7,8};  // list of program change messages to send
byte controlChanges[] = {66,67,68,69,70,71,72,73,74};
byte channel = 0; // for musicians this is channel 1


// Variables will change:
//int buttonPushCounter = 0;   // counter for the number of button presses
int up_buttonState = 0;         // current state of the up button
int up_lastButtonState = 0;     // previous state of the up button

int down_buttonState = 0;         // current state of the down button
int down_lastButtonState = 0;     // previous state of the down button
//bool bPress = false;

void setup() {
  for(int i =0;i< sizeof(buttonPin); i++){ // initialise input pins  
    pinMode(buttonPin[i], INPUT_PULLUP); // wire all buttons between input and ground
    pinMode(ledPin[i], OUTPUT);
  //}
//{
  //Serial.begin(9600);
 // pinMode( Up_buttonPin , INPUT_PULLUP);
 // pinMode( Down_buttonPin , INPUT_PULLUP);
  
}
}

void loop() {
  for(int i =0;i< sizeof(buttonPin); i++){  // look at all pins
  buttonState[i] = digitalRead(buttonPin[i]); 
  if(buttonState[i] == LOW && lastButtonState[i] == HIGH) { // remember how you wired your buttons LOW = pressed
    
    ledOffAll();
    digitalWrite(ledPin[i],HIGH);
    controlChange(channel, control, value, controlChanges[i]); // send the program change message
       
    MidiUSB.flush();
   }
   lastButtonState[i] = buttonState[i];
  }
}

void ledOffAll() {
    for(int i = 0 ; i< sizeof(ledPin); i++){
     digitalWrite(ledPin[i], LOW); 
    }
}

void programChange(byte channel, byte patch) {
  midiEventPacket_t event = {0x0C, 0xC0 | channel, patch};
  MidiUSB.sendMIDI(event);
   MidiUSB.flush();
}
   
void  controlChange(byte channel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
  MidiUSB.sendMIDI(event);
  MidiUSB.flush();

{
     
   }
  
}

1 Like
void  controlChange(byte channel, byte control, byte value)

controlChange is defined to take three parameters, all bytes.

controlChange(channel, control, value, controlChanges[i]);

Attempt to use controlChange with four parameters... and maybe I missed it but I couldn't find a declaration for control or for value.

... and the error message is about control not being declared.

Yes, good point. But how do I "declare" them? Interestingly, the error would be "too few arguments to function 'void controlChange(byte, byte, byte)' " when I put in 'channel, controlChange *" only. *
This works for programChange
```

  • programChange(channel, programChanges[i]*
    ```
    Thanks for taking time to answer.
   controlChange(channel, control, value, controlChanges[i]); // send the program change message

Replace 'control' with 'controlChanges[ i ]' instead of trying to add it as an extra parameter.

Steve

1 Like

..and place "value" at the end? It will result in a "value not declared" error. But... it did suddenly work when I put 127 in its place! Still experimenting... thank you for the answer.

How about (not tested):

  byte value = 127 ;
.
.
.
 controlChange(channel, controlChanges[ i ], value ); // send the program change message

vaj4088:
How about (not tested):

  byte value = 127 ;

.
.
.
controlChange(channel, controlChanges[ i ], value ); // send the program change message





This is exactly what i did and the errror went away. Thank you. I'm experimenting on how to combine the Controlchange and program change. 5 buttons will be for PCs and 4 will be for CCs.