source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/04.Communication/Midi/Midi.ino @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 1.2 KB
Line 
1/*
2 MIDI note player
3
4 This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
5 If this circuit is connected to a MIDI synth, it will play
6 the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.
7
8
9 The circuit:
10 * digital in 1 connected to MIDI jack pin 5
11 * MIDI jack pin 2 connected to ground
12 * MIDI jack pin 4 connected to +5V through 220-ohm resistor
13 Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
14
15 created 13 Jun 2006
16 modified 13 Aug 2012
17 by Tom Igoe
18
19 This example code is in the public domain.
20
21 http://www.arduino.cc/en/Tutorial/Midi
22
23 */
24
25void setup() {
26  //  Set MIDI baud rate:
27  Serial.begin(31250);
28}
29
30void loop() {
31  // play notes from F#-0 (0x1E) to F#-5 (0x5A):
32  for (int note = 0x1E; note < 0x5A; note ++) {
33    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
34    noteOn(0x90, note, 0x45);
35    delay(100);
36    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
37    noteOn(0x90, note, 0x00);
38    delay(100);
39  }
40}
41
42//  plays a MIDI note.  Doesn't check to see that
43//  cmd is greater than 127, or that data values are  less than 127:
44void noteOn(int cmd, int pitch, int velocity) {
45  Serial.write(cmd);
46  Serial.write(pitch);
47  Serial.write(velocity);
48}
49
Note: See TracBrowser for help on using the repository browser.