And finally if you connect eight buttons to pins 2 - 8 like in the diagram shown above (i.e. pin 2,3,4,5,6,7,8 --> switch || switch --> ground):
Then the following code should give you some ideas.
I haven't tried out any of these. YMMV.
byte MIDI_pitch[] = {60,62,63,65,67,69,71,72}; // value of MIDI pitch to associate with button
byte MIDI_velocity[] = {127,127,127,127,127,127,127,127}; // value of MIDI velocity to associate with button
byte MIDI_channel[] = {0,0,0,0,0,0,0,0}; // value of MIDI channel to associate with button
byte previous[8]; // place to store previous data byte for comparison
byte current; // place to store current data byte for comparison
void setup() { // let's begin..
Serial.begin(57600); // open serial port
pinMode(2, INPUT); // set pin mode of button to input
digitalWrite(2, HIGH); // activate internal Arduino resistor
pinMode(3, INPUT); // set pin mode of button to input
digitalWrite(2, HIGH); // activate internal Arduino resistor
pinMode(4, INPUT); // set pin mode of button to input
digitalWrite(2, HIGH); // activate internal Arduino resistor
pinMode(5, INPUT); // set pin mode of button to input
digitalWrite(2, HIGH); // activate internal Arduino resistor
pinMode(6, INPUT); // set pin mode of button to input
digitalWrite(2, HIGH); // activate internal Arduino resistor
pinMode(7, INPUT); // set pin mode of button to input
digitalWrite(2, HIGH); // activate internal Arduino resistor
pinMode(8, INPUT); // set pin mode of button to input
digitalWrite(2, HIGH); // activate internal Arduino resistor
pinMode(9, INPUT); // set pin mode of button to input
digitalWrite(2, HIGH); // activate internal Arduino resistor
} // end of the beginning
void loop() { // let's loop...
for(int i = 0; i < 8; i++) {
current = digitalRead(i+2); // read the current state of the button
if(current != previous[i]) { // compare the current state of the button to previous state
previous[i] = current; // if it's change, store the current for future comparison
Serial.write(0x90 + MIDI_channel[i]); // send MIDI status byte for note on event
Serial.write(MIDI_pitch[i]); // send MIDI data byte for pitch component
Serial.write((1 - current) * MIDI_velocity[i]); // send MIDI data byte for velocity component
} // end if
delay(10); // debounce
}
} // end loop