Debian Codegraph @

examples/04.Communication/Midi/Midi.ino

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