MIDI 音符播放器
硬件要求
电路 根据MIDI说明书,所有MIDI连接器都是母座。这里是怎样把连接器连接到开发板。
原理图 样例代码 注意:如果你用带有ATmega3U4的开发板(如DUE或者Leonardo),请根据下面程序用Serial1来替换Serial。 /* MIDI note player This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data. If this circuit is connected to a MIDI synth, it will play the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence. The circuit: * digital in 1 connected to MIDI jack pin 5 * MIDI jack pin 2 connected to ground * MIDI jack pin 4 connected to +5V through 220-ohm resistor Attach a MIDI cable to the jack, then to a MIDI synth, and play music. created 13 Jun 2006 modified 13 Aug 2012 by Tom Igoe This example code is in the public domain.http://www./en/Tutorial/Midi */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);=""> [Get Code] 更多
|
|