Hola compañero alvaro revueltas exelente aportacion, tengo una duda, yo construi un controlador midi con pads usando un codigo que encontre en el foro, mi pregunta es como le integraria la utlidad que tu mencionas al codigo, soy muy novato en esto del arduino y me gustaria mejorar mi controlador y dejar de depender de la interfase midi usb que tengo y aparte darle alimentacion por el puerto usd del arduino, te dejo el codigo espero puedas ayudarme.
//linea 1
const int buttonDoPin = 2;//numeracion de pin
const int button2Pin = 3;
const int button3Pin = 4;
const int button4Pin = 5;
//linea 2
const int button5Pin = 8;
const int button6Pin = 9;
const int button7Pin = 10;
const int button8Pin = 11;
//linea 3
const int button9Pin = 22;
const int button10Pin = 24;
const int button11Pin = 26;
const int button12Pin = 28;
//linea 4
const int button13Pin = 23;
const int button14Pin = 25;
const int button15Pin = 27;
const int button16Pin = 29;
//linea 1
int noteDo = 36; //MIDI note 69=A (440hz)
int note2= 37;
int note3= 38;
int note4= 39;
//linea 2
int note5= 40;
int note6= 41;
int note7= 42;
int note8= 43;
//linea3
int note9= 44;
int note10= 45;
int note11= 46;
int note12= 47;
// linea4
int note13= 48;
int note14= 49;
int note15= 50;
int note16= 51;
int buttonDoState = 0;// current state of the button
int button2State = 0;
int button3State = 0;
int button4State = 0;
int button5State = 0;
int button6State = 0;
int button7State = 0;
int button8State = 0;
int button9State = 0;
int button10State = 0;
int button11State = 0;
int button12State = 0;
int button13State = 0;
int button14State = 0;
int button15State = 0;
int button16State = 0;
int lastButtonDoState = 0;
int lastButton2State = 0;
int lastButton3State = 0;
int lastButton4State = 0;
int lastButton5State = 0;
int lastButton6State = 0;
int lastButton7State = 0;
int lastButton8State = 0;
int lastButton9State = 0;
int lastButton10State = 0;
int lastButton11State = 0;
int lastButton12State = 0;
int lastButton13State = 0;
int lastButton14State = 0;
int lastButton15State = 0;
int lastButton16State = 0;
int val;
void setup() {
// initialize the button pin as a input:
pinMode(buttonDoPin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(button3Pin, INPUT);
pinMode(button4Pin, INPUT);
pinMode(button5Pin, INPUT);
pinMode(button6Pin, INPUT);
pinMode(button7Pin, INPUT);
pinMode(button8Pin, INPUT);
pinMode(button9Pin, INPUT);
pinMode(button10Pin, INPUT);
pinMode(button11Pin, INPUT);
pinMode(button12Pin, INPUT);
pinMode(button13Pin, INPUT);
pinMode(button14Pin, INPUT);
pinMode(button15Pin, INPUT);
pinMode(button16Pin, INPUT);
// initialize serial communication:
// Set MIDI baud rate:
Serial.begin(31250);
}
void loop() {
buttonDoState = digitalRead(buttonDoPin);
if (buttonDoState == 0)
{ noteOn(0x90, noteDo, 0x00);}
else if (buttonDoState == lastButtonDoState)
{}
else { noteOn(0x90, noteDo, 0x45);}
button2State = digitalRead(button2Pin);
if (button2State == 0)
{ noteOn(0x90, note2, 0x00);}
else if (button2State == lastButton2State)
{}
else { noteOn(0x90, note2, 0x45);}
button3State = digitalRead(button3Pin);
if (button3State == 0)
{ noteOn(0x90, note3, 0x00);}
else if (button3State == lastButton3State)
{}
else { noteOn(0x90, note3, 0x45);}
button4State = digitalRead(button4Pin);
if (button4State == 0)
{ noteOn(0x90, note4, 0x00);}
else if (button4State == lastButton4State)
{}
else { noteOn(0x90, note4, 0x45);}
button5State = digitalRead(button5Pin);
if (button5State == 0)
{ noteOn(0x90, note5, 0x00);}
else if (button5State == lastButton5State)
{}
else { noteOn(0x90, note5, 0x45);}
button6State = digitalRead(button6Pin);
if (button6State == 0)
{ noteOn(0x90, note6, 0x00);}
else if (button6State == lastButton6State)
{}
else { noteOn(0x90, note6, 0x45);}
button7State = digitalRead(button7Pin);
if (button7State == 0)
{ noteOn(0x90, note7, 0x00);}
else if (button7State == lastButton7State)
{}
else { noteOn(0x90, note7, 0x45);}
button8State = digitalRead(button8Pin);
if (button8State == 0)
{ noteOn(0x90, note8, 0x00);}
else if (button8State == lastButton8State)
{}
else { noteOn(0x90, note8, 0x45);}
button9State = digitalRead(button9Pin);
if (button9State == 0)
{ noteOn(0x90, note9, 0x00);}
else if (button9State == lastButton9State)
{}
else { noteOn(0x90, note9, 0x45);}
button10State = digitalRead(button10Pin);
if (button10State == 0)
{ noteOn(0x90, note10, 0x00);}
else if (button10State == lastButton10State)
{}
else { noteOn(0x90, note10, 0x45);}
button11State = digitalRead(button11Pin);
if (button11State == 0)
{ noteOn(0x90, note11, 0x00);}
else if (button11State == lastButton11State)
{}
else { noteOn(0x90, note11, 0x45);}
button12State = digitalRead(button12Pin);
if (button12State == 0)
{ noteOn(0x90, note12, 0x00);}
else if (button12State == lastButton12State)
{}
else { noteOn(0x90, note12, 0x45);}
button13State = digitalRead(button13Pin);
if (button13State == 0)
{ noteOn(0x90, note13, 0x00);}
else if (button13State == lastButton13State)
{}
else { noteOn(0x90, note13, 0x45);}
button14State = digitalRead(button14Pin);
if (button14State == 0)
{ noteOn(0x90, note14, 0x00);}
else if (button14State == lastButton14State)
{}
else { noteOn(0x90, note14, 0x45);}
button15State = digitalRead(button15Pin);
if (button15State == 0)
{ noteOn(0x90, note15, 0x00);}
else if (button15State == lastButton15State)
{}
else { noteOn(0x90, note15, 0x45);}
button16State = digitalRead(button16Pin);
if (button16State == 0)
{ noteOn(0x90, note16, 0x00);}
else if (button16State == lastButton16State)
{}
else { noteOn(0x90, note16, 0x45);}
lastButtonDoState = buttonDoState;
lastButton2State = button2State;
lastButton3State = button3State;
lastButton4State = button4State;
lastButton5State = button5State;
lastButton6State = button6State;
lastButton7State = button7State;
lastButton8State = button8State;
lastButton9State = button9State;
lastButton10State = button10State;
lastButton11State = button11State;
lastButton12State = button12State;
lastButton13State = button13State;
lastButton14State = button14State;
lastButton15State = button15State;
lastButton16State = button16State;
}
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(byte (cmd));
Serial.write(byte (pitch));
Serial.write(byte (velocity));
}