Arduino | 您所在的位置:网站首页 › miti接口 › Arduino |
Learning Examples | Foundations | Hacking | Links Examples > Communication MIDI Note Player本教程展示如何用Arduino来播放MIDI音符。 MIDI, the Musical Instrument Digital Interface, 是一个非常有用的协议,能够用来控制 合成,时序,和其他音乐设备。 MIDI设备一般分为两大类:控制器(即基于人类活动产生的MIDI信号的设备)和合成器(包括采样器,音序器,等等)。后者接收MIDI数据,能够产生使声,光,或是其他一些效果。 MIDI是一个串行协议,波特率为31250 bps 。Arduino自带的串口(包括MEGA),都可以发送此波特率的数据。 MIDI流分为两种类型:命令字节和数据字节。命令字节一般是128或更大的数,16进制中表示为 0x80到0xFF。数据字节一般小于127,16进制中为0x00 到0x7F。命令字节包括诸如note on,note off,pitch bend等。数据流包括音符的音高,速度,响度和 amount of picht bend等等。如果需要了解详细的信息,请参阅MIDI规范MIDI Protocol Guides 。 由于MIDIbank和设备以16为基数分组,所以MIDI数据一般表示为16进制。 了解更多请看这里 MIDI介绍 或者这个 示例. 硬件需求 Arduino 板 (1) MIDI 接口 (1) 220 欧姆电阻 连接线 MIDI设备 (可选, 测试用) CircuitMIDI的规范规定所有的MIDI连接器都是母头,下面讲解如何将MIDI连接器和Arduino连接起来 Arduino 的digital pin 1 连接到 MIDI 接口的 pin 5 MIDI 接口的 pin 2 连接到地GND。 MIDI 接口的 pin 4 串联一个220欧姆的电阻后连接至+5V。点击图片即可看到大图 图片是用软件 Fritzing画的. 需要看到更多的电路图例子,点这里Fritzing project page 原理图 点击图片即可得到大图 click the image to enlarge Code/* 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 30 Aug 2011 by Tom Igoe This example code is in the public domain. http://arduino.cc/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 |
CopyRight 2018-2019 实验室设备网 版权所有 |