MIDIUSB sending CC messages

Hi all,

im a bit of a newcomer to arduino,
i'm trying to build an arduino midi controller. i need to send out CC messages while lighting up LEDs accordingly
the LED part i figured out, and even managed to debounce
the CC message part i got from someone who posted his code, and i dont think it works the way it should
i want each button to have an assigned note, and turn a plugin on and off

this is my code:

#include <MIDIUSB.h>

int iLED8state = LOW; // LED on or off
int iLED9state = LOW;
int iLED10state = LOW;
int iLED11state = LOW;
int iLED12state = LOW;
int iLED13state = LOW;
long lastDebounceTime = 0;  // the last time the output pin was toggled, long since counter can go high
long debounceDelay = 250;    // the debounce time; increase if the output flickers


void setup() {
  Serial.begin(115200);
  pinMode( 2 , INPUT_PULLUP );
  pinMode( 3 , INPUT_PULLUP );
  pinMode( 4 , INPUT_PULLUP );
  pinMode( 5 , INPUT_PULLUP );
  pinMode( 6 , INPUT_PULLUP );
  pinMode( 7 , INPUT_PULLUP );
  

  pinMode(8, OUTPUT);  // LED
  pinMode(9, OUTPUT);  // LED
  pinMode(10, OUTPUT);  // LED
  pinMode(11, OUTPUT);  // LED
  pinMode(12, OUTPUT);  // LED
  pinMode(13, OUTPUT);  // LED
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);
}

// First parameter is the event type (0x0B = control change).
// Second parameter is the event type, combined with the channel.
// Third parameter is the control number number (0-119).
// Fourth parameter is the control value (0-127).

void controlChange(byte channel, byte control, byte value) {
  midiEventPacket_t packet = {0x0B, 0xB0 | channel, control, value};
  MidiUSB.sendMIDI(packet);
}

void programChange(byte channel, byte program) {
  midiEventPacket_t packet = {0x0C, 0xC0 | channel, program, 0};
  MidiUSB.sendMIDI(packet);
}

void change_preset(byte preset){
  controlChange(0, 64, 0);  // channel 0, LSB Bank Select, Bank 0
  programChange(0, preset); // channel 0, Preset preset
  MidiUSB.flush();
}

void footswitch_led_control(int led_pin, int footswitch, int midi_send) {
	iLED8state=digitalRead(led_pin);
	
			if ( (millis() - lastDebounceTime) > debounceDelay)
			{
				if (!digitalRead(footswitch))
				{		   
				change_preset(midi_send);
					if (iLED8state==LOW)
					{
						digitalWrite(led_pin, HIGH);
						lastDebounceTime = millis(); //set the current time
					} 
					else  
					{
						digitalWrite (led_pin, LOW);
						lastDebounceTime = millis(); //set the current time
					}
				}	 
			}

}



void loop() {
	
		
	footswitch_led_control(8,2,7);
	footswitch_led_control(9,3,6);
	footswitch_led_control(10,4,5);
	footswitch_led_control(11,5,4);
	footswitch_led_control(12,6,0);
 	footswitch_led_control(13,7,1); 
	/*iLED8state=digitalRead(8);

	  if (!digitalRead(2))
	  {		   
      change_preset(7);
		  if (iLED8state==LOW)
	  	{
			 digitalWrite(8, HIGH);
      } 
        else  
        {
		  	digitalWrite (8, LOW);
	    	}
	  }	  
  //iLED9state=digitalRead(9);

	  if (!digitalRead(3))
	  {		   
      change_preset(6);
		  if (iLED9state==LOW)
	  	{
			 digitalWrite(9, HIGH);
      } 
        else  
        {
		  	digitalWrite (9, LOW);
	    	}
	  }	  
  //if (!digitalRead(4)) change_preset(5) digitalWrite(10, HIGH);
  //if (!digitalRead(5)) change_preset(4) digitalWrite(11, HIGH);
  //if (!digitalRead(6)) change_preset(0) digitalWrite(12, HIGH);
  //if (!digitalRead(7)) change_preset(1) digitalWrite(13, HIGH);*/
}

i hope someone can help me make sense of the MIDI-send
thanks i advance for the hel

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.

Describe what's happening and what's not happening. What deviates from desired action and how.

hi,
thanks for the quick reply!

i connected it to some midi receiving computer programs and i dont see a control change happening when i press the button/
for instance - reaper: the leonardo is recognized as a MIDi device, i arm the track for recording, set up the input as a midi track with the leonardo chosen as the device - start recording - and when i press buttons there is some sort of response but not on any channel and it looks the same
i tried using mixxx, and it didnt read any control change when i put it in learning mode

Words that only midi designers can gain anything from. Not my field but other helpers will "get it"?

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