MidiUSB.h Messing up windows usb ports and other

Hi, I'm having an issue with the MIDIUSB.h library. More specifically: I upload my code on my arduino pro micro (chinese, not original), it works fine and on my DAW (reaper) it does everything I need. The problems come when I close the DAW after I used it with my arduino, since every usb port on my PC stop working (except for the one that already have peripherals attached). Furthermore windows doesn't shut down completely. After restarting the PC using the power button everything start working again.
Has everyone ever witnessed a similar problem?
Thanks

My code is, they are 10 buttons sending simple midi control changes:

#include "MIDIUSB.h"
#include "Arduino.h"
#include "avdweb_Switch.h"


Switch buttonGND1 = Switch(5); 
Switch buttonGND2 = Switch(6);  
Switch buttonGND3 = Switch(7);   
Switch buttonGND4 = Switch(8); 
Switch buttonGND5 = Switch(9);  
Switch buttonGND6 = Switch(15); 
Switch buttonGND7 = Switch(20); 
Switch buttonGND8 = Switch(18);  
Switch buttonGND9 = Switch(21);  
Switch buttonGND10 = Switch(19); 
int LED1 = 1;
int LED2 = 0;
int LED3 = 2;
int LED4 = 3;
int LED5 = 4;
int LED6 = 10;
int LED8 = 16;
int LED10 =14;
int LEDNP1 = 22;
int LEDNP2 = 23;
int stateLED1 = 0;
int stateLED2 = 0;
int stateLED3 = 0;
int stateLED4 = 0;
int stateLED5 = 0;
int stateLED6 = 0;
int stateLED8 = 0;
int stateLED10 = 0;
int stateLEDNP1 = 0;
int stateLEDNP2 = 0;

int previous = 0;



void noteOn(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOn);
}

void noteOff(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOff);
}
void controlChange(byte channel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
  MidiUSB.sendMIDI(event);
}

void setup() {
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  pinMode(LED8, OUTPUT);
  pinMode(LED10, OUTPUT);
  //Serial.begin (9600);
  //Serial.begin (31250);
  Serial.begin(115200);

}

void loop() 
{
  
 buttonGND1.poll();  
    if(buttonGND1.pushed()) {
      if(stateLED1 == 255){
        stateLED1 = 0; 
        controlChange(15,106,0); // channel, control, value
        MidiUSB.flush();}
      else {
        stateLED1 = 255; 
        controlChange(15,106,127); // channel, control, value
        MidiUSB.flush();}
      digitalWrite(LED1, stateLED1);    }

 buttonGND2.poll();  //103
    if(buttonGND2.pushed()) {
      if(stateLED2 == 255){
        stateLED2 = 0; 
        controlChange(15,105,0); // channel, control, value
        MidiUSB.flush();}
      else {
        stateLED2 = 255; 
        controlChange(15,105,127); // channel, control, value
        MidiUSB.flush();}
      digitalWrite(LED2, stateLED2);    }
  
 buttonGND3.poll();  //104
    if(buttonGND3.pushed()) {
      if(stateLED3 == 255){
        stateLED3 = 0; 
        controlChange(15,104,0); // channel, control, value
        MidiUSB.flush();}
      else {
        stateLED3 = 255; 
        controlChange(15,104,127); // channel, control, value
        MidiUSB.flush();}
      digitalWrite(LED3, stateLED3);    }

 buttonGND4.poll();  //105
    if(buttonGND4.pushed()) {
      if(stateLED4 == 255){
        stateLED4 = 0; 
        controlChange(15,103,0); // channel, control, value
        MidiUSB.flush();}
      else {
        stateLED4 = 255; 
        controlChange(15,103,127); // channel, control, value
        MidiUSB.flush();}
      digitalWrite(LED4, stateLED4);    }
   
  buttonGND5.poll();  //106
    if(buttonGND5.pushed()) {
      if(stateLED5 == 255){
        stateLED5 = 0; 
        controlChange(15,102,0); // channel, control, value
        MidiUSB.flush();}
      else {
        stateLED5 = 255; 
        controlChange(15,102,127); // channel, control, value
        MidiUSB.flush();}
      digitalWrite(LED5, stateLED5);    }
   
  buttonGND6.poll();                    //Reference 3
    if(buttonGND6.pushed()) {
      if(stateLED6 == 255){
        stateLED6 = 0; 
        controlChange(15,109,0); 
        controlChange(15,108,0); 
        controlChange(15,107,0);  
        MidiUSB.flush(); }
      else {
        stateLED6 = 255; 
        stateLED8 = 0; 
        stateLED10 = 0; 
        controlChange(15,109,0); 
        controlChange(15,108,0); 
        controlChange(15,107,127);  
        MidiUSB.flush(); }
      digitalWrite(LED6, stateLED6);
      digitalWrite(LED8, stateLED8);
      digitalWrite(LED10, stateLED10);}

  buttonGND7.poll();  //110
    if(buttonGND7.pushed()) {
      if(stateLEDNP1 == 255){
        stateLEDNP1 = 0; 
        controlChange(15,110,0); // channel, control, value
        MidiUSB.flush();}
      else {
        stateLEDNP1 = 255; 
        controlChange(15,110,127); // channel, control, value
        MidiUSB.flush();}
      digitalWrite(LEDNP1, stateLEDNP1);    }

   buttonGND8.poll();                    //Reference 2
    if(buttonGND8.pushed()) {
      if(stateLED8 == 255){
        stateLED8 = 0; 
        controlChange(15,107,0); 
        controlChange(15,109,0); 
        controlChange(15,108,0);  
        MidiUSB.flush(); }
      else {
        stateLED8 = 255; 
        stateLED10 = 0; 
        stateLED6 = 0; 
        controlChange(15,109,0); 
        controlChange(15,107,0); 
        controlChange(15,108,127);  
        MidiUSB.flush(); }
      digitalWrite(LED6, stateLED6);
      digitalWrite(LED8, stateLED8);
      digitalWrite(LED10, stateLED10);}

   buttonGND9.poll();  //111
    if(buttonGND9.pushed()) {
      if(stateLEDNP2 == 255){
        stateLEDNP2 = 0; 
        controlChange(15,111,0); // channel, control, value
        MidiUSB.flush();}
      else {
        stateLEDNP2 = 255; 
        controlChange(15,111,127); // channel, control, value
        MidiUSB.flush();}
      digitalWrite(LEDNP2, stateLEDNP2);    }

   buttonGND10.poll();                     //Reference 1
    if(buttonGND10.pushed()) {
      if(stateLED10 == 255){
        stateLED10 = 0; 
        controlChange(15,107,0); 
        controlChange(15,108,0); 
        controlChange(15,109,0);  
        MidiUSB.flush();    }
      else {
        stateLED10 = 255; 
        stateLED8 = 0; 
        stateLED6 = 0; 
        controlChange(15,107,0); 
        controlChange(15,108,0); 
        controlChange(15,109,127);  
        MidiUSB.flush(); }
      digitalWrite(LED6, stateLED6);
      digitalWrite(LED8, stateLED8);
      digitalWrite(LED10, stateLED10);}
  }

Your post was MOVED to its current location as it is more suitable.

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