Thanks to all people!
My idea of use 4 arduino pro mini is because is smaller, and I have 64 true inputs. I have read that if I multiplex the input, I cant push 2 or more buttons at the time, because multiplexer cant send more that 1 date at the time. I can use multiplexing and have 2 or more buttons pressed at the time?
Attach my actually code, I used 4 buttons and 4 leds (I will change for RGB leds with Common Anode):
#include <MIDI.h>
int action=2;
byte incomingByte;
byte note;
byte velocity;
//line 1
const int buttonDoPin = 2;
const int button2Pin = 3;
const int button3Pin = 4;
const int button4Pin = 5;
//line 1
int noteDo = 36;
int note2= 37;
int note3= 38;
int note4= 39;
int buttonDoState = 0;
int button2State = 0;
int button3State = 0;
int button4State = 0;
int lastButtonDoState = 0;
int lastButton2State = 0;
int lastButton3State = 0;
int lastButton4State = 0;
int val;
void setup() {
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(buttonDoPin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(button3Pin, INPUT);
pinMode(button4Pin, INPUT);
MIDI.begin(MIDI_CHANNEL_OMNI);
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte== 144){
action=1;
}else if (incomingByte== 128){
action=0;
}else if ( (action==0)&&(note==0) ){
note=incomingByte;
playNote(note, 0);
note=0;
velocity=0;
action=2;
}else if ( (action==1)&&(note==0) ){
note=incomingByte;
}else if ( (action==1)&&(note!=0) ){
velocity=incomingByte;
playNote(note, velocity);
note=0;
velocity=0;
action=0;
}else{
//Nothing
}
}
buttonDoState = digitalRead(buttonDoPin);
if (buttonDoState == 0)
{ MIDI.sendNoteOff(noteDo,0,1);}
else if (buttonDoState == lastButtonDoState)
{}
else { MIDI.sendNoteOn(noteDo,127,1);}
button2State = digitalRead(button2Pin);
if (button2State == 0)
{ MIDI.sendNoteOff(note2,0,1);}
else if (button2State == lastButton2State)
{}
else { MIDI.sendNoteOn(note2,127,1);}
button3State = digitalRead(button3Pin);
if (button3State == 0)
{ MIDI.sendNoteOff(note3,0,1);}
else if (button3State == lastButton3State)
{}
else { MIDI.sendNoteOn(note3,127,1);}
button4State = digitalRead(button4Pin);
if (button4State == 0)
{ MIDI.sendNoteOff(note4,0,1);}
else if (button4State == lastButton4State)
{}
else { MIDI.sendNoteOn(note4,127,1);}
lastButtonDoState = buttonDoState;
lastButton2State = button2State;
lastButton3State = button3State;
lastButton4State = button4State;
}
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(byte (cmd));
Serial.write(byte (pitch));
Serial.write(byte (velocity));
}
void playNote(byte note, byte velocity){
int value=LOW;
if (velocity >10){
value=HIGH;
}else{
value=LOW;
}
if(note==36){
digitalWrite(8, value);
}
if(note==37){
digitalWrite(9, value);
}
if(note==38){
digitalWrite(10, value);
}
if(note==39){
digitalWrite(11, value);
}
}
Thanks everybody
Greetings