//mux variables #include const byte input = 11; // digital input to arduino from mux const byte c=10; const byte b=9; const byte a=8; const int button1Pin = 4; const int button2Pin = 5; const int button3Pin = 6; const int button4Pin = 7; const int DEFAULT_MIDI_CHANNEL = 1; int button1State = 0; int button2State = 0; int button3State = 0; int button4State = 0; int note1 = 0; int note2 = 0; int note3 = 0; int note4 = 0; int note5 = 0; int note6 = 0; int note7 = 0; int note8 = 0; int note9 = 0; int note10 = 0; int note11 = 0; int note12 = 0; // to store the values from mux // bool val[] = {0,0,0,0,0,0,0,0}; byte numero; MIDI_CREATE_DEFAULT_INSTANCE(); void setup() { MIDI.begin(MIDI_CHANNEL_OMNI); Serial.begin(115200); pinMode(c, OUTPUT); pinMode(b, OUTPUT); pinMode(a, OUTPUT); pinMode(button1Pin, INPUT); pinMode(button2Pin, INPUT); pinMode(button3Pin, INPUT); pinMode(button4Pin, INPUT); pinMode(input, INPUT); } void loop() { int button1State = digitalRead(button1Pin); int button2State = digitalRead(button2Pin); int button3State = digitalRead(button3Pin); int button4State = digitalRead(button4Pin); numero = 0; for(byte i=0;i<8;i++) { numero = numero | ( digitalRead(input) << i) ; //select mux input digitalWrite(a, bitRead(i, 0)); digitalWrite(b, bitRead(i, 1)); digitalWrite(c, bitRead(i, 2)); button1State = digitalRead(button1Pin); button2State = digitalRead(button2Pin); button3State = digitalRead(button3Pin); button4State = digitalRead(button4Pin); } if (button1State == HIGH) { // if note not playing if (note1 == 0) { // play note (note number, velocity, channel) // more info: http://arduinomidilib.sourceforge.net/a00001.html // MIDI notes chart http://www.phys.unsw.edu.au/jw/notes.html // 55 = G3, 127 = trigger note with max volume MIDI.sendNoteOn(42, 127, DEFAULT_MIDI_CHANNEL); // note is playing note1 = 1; } // when button released } else { // if note playing if (note1 == 1) { // if playing - stop MIDI.sendNoteOff(42, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note1 = 0; } if (button2State == HIGH) { // if note not playing if (note2 == 0) { MIDI.sendNoteOn(43, 127, DEFAULT_MIDI_CHANNEL); // note is playing note2 = 1; } // when button released } else { // if note playing if (note2 == 1) { // if playing - stop MIDI.sendNoteOff(43, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note2 = 0; } if (button3State == HIGH) { // if note not playing if (note3 == 0) { MIDI.sendNoteOn(44, 127, DEFAULT_MIDI_CHANNEL); // note is playing note3 = 1; } // when button released } else { // if note playing if (note3 == 1) { // if playing - stop MIDI.sendNoteOff(44, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note3 = 0; } if (button4State == HIGH) { // if note not playing if (note4 == 0) { MIDI.sendNoteOn(45, 127, DEFAULT_MIDI_CHANNEL); // note is playing note4 = 1; } // when button released } else { // if note playing if (note4 == 1) { // if playing - stop MIDI.sendNoteOff(45, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note4 = 0; } if (numero == 1) { // if note not playing if (note5 == 0) { MIDI.sendNoteOn(46, 127, DEFAULT_MIDI_CHANNEL); // note is playing note5 = 1; } // when button released } else { // if note playing if (note5 == 1) { // if playing - stop MIDI.sendNoteOff(46, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note5 = 0; } if (numero == 2) { // if note not playing if (note6 == 0) { MIDI.sendNoteOn(47, 127, DEFAULT_MIDI_CHANNEL); // note is playing note6 = 1; } // when button released } else { // if note playing if (note6 == 1) { // if playing - stop MIDI.sendNoteOff(47, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note6 = 0; } if (numero == 4) { // if note not playing if (note7 == 0) { MIDI.sendNoteOn(48, 127, DEFAULT_MIDI_CHANNEL); // note is playing note7 = 1; } // when button released } else { // if note playing if (note7 == 1) { // if playing - stop MIDI.sendNoteOff(48, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note7 = 0; } if (numero == 8) { // if note not playing if (note8 == 0) { MIDI.sendNoteOn(49, 127, DEFAULT_MIDI_CHANNEL); // note is playing note8 = 1; } // when button released } else { // if note playing if (note8 == 1) { // if playing - stop MIDI.sendNoteOff(49, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note8 = 0; } if (numero == 16) { // if note not playing if (note9 == 0) { MIDI.sendNoteOn(50, 127, DEFAULT_MIDI_CHANNEL); // note is playing note9 = 1; } // when button released } else { // if note playing if (note9 == 1) { // if playing - stop MIDI.sendNoteOff(50, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note9 = 0; } if (numero == 32) { // if note not playing if (note10 == 0) { MIDI.sendNoteOn(51, 127, DEFAULT_MIDI_CHANNEL); // note is playing note10 = 1; } // when button released } else { // if note playing if (note10 == 1) { // if playing - stop MIDI.sendNoteOff(51, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note10 = 0; } if (numero == 64) { // if note not playing if (note11 == 0) { MIDI.sendNoteOn(52, 127, DEFAULT_MIDI_CHANNEL); // note is playing note11 = 1; } // when button released } else { // if note playing if (note11 == 1) { // if playing - stop MIDI.sendNoteOff(52, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note11 = 0; } if (numero == 128) { // if note not playing if (note12 == 0) { MIDI.sendNoteOn(53, 127, DEFAULT_MIDI_CHANNEL); // note is playing note12 = 1; } // when button released } else { // if note playing if (note12 == 1) { // if playing - stop MIDI.sendNoteOff(53, 0, DEFAULT_MIDI_CHANNEL); } // if button released note is off note12 = 0; } //serial printing //Serial.print("Numero: "); //Serial.println(numero); }