Der Arduino kann auch MIDI und ist somit auch als “Musikinstrument“ nutzbar…

Schaltungsaufbau:

MIDI-Pin 2 (schwarzes Kabel) führt zu Ground (GND).

MIDI Pin 4 (weißes Kabel) führt über einen Widerstand an 5 Volt.

MIDI Pin 5 (grünes Kabel) führt an Arduino-Pin 1.

Die MIDI-Buchse am Steckboard ist ein MIDI-Out und sendet (in meinem Fall) Daten an ein Yamaha Soundmodul.

Arduino-Code für MIDI-Projekt 1:

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250);
}

void loop() {
  // play notes from F#-0 (0x1E) to F#-5 (0x5A):
  for (int note = 0x1E; note < 0x5A; note ++) {
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note, 0x45);
    delay(100);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note, 0x00);  
    delay(100);
  }
}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

Arduino-Code für MIDI-Projekt 2:

void setup() {
Serial.begin(31250);
}

void loop() {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, 0x59, 0x45);
delay(1000);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, 0x59, 0x00);  
delay(1000);

noteOn(0x99, 0x10, 0x45);
delay(1000);
noteOn(0x99, 0x10, 0x00);
delay(1000);

}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}

Arduino-Code für MIDI-Projekt 3:

int d = 250;

void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
}

void loop() {

/*
Bass Drum = 0x23 
Snare Drum = 0x26
*/

noteOn(0x99, 0x23, 0x45);
delay(d);
noteOn(0x99, 0x23, 0x00);
delay(d);
noteOn(0x99, 0x26, 0x45);
delay(d);
noteOn(0x99, 0x26, 0x00);
delay(d);
noteOn(0x99, 0x23, 0x45);
delay(d);
noteOn(0x99, 0x23, 0x00);
delay(d);
noteOn(0x99, 0x26, 0x45);
delay(d);
noteOn(0x99, 0x26, 0x00);
delay(d);
noteOn(0x99, 0x23, 0x45);
delay(d);
noteOn(0x99, 0x23, 0x00);
delay(d);
noteOn(0x99, 0x26, 0x45);
delay(d);
noteOn(0x99, 0x26, 0x00);
delay(d);

}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

Von Torsten