~ubuntu-branches/ubuntu/precise/arduino/precise

« back to all changes in this revision

Viewing changes to examples/Communication/MIDI/Midi.pde

  • Committer: Bazaar Package Importer
  • Author(s): Scott Howard
  • Date: 2010-04-13 22:32:24 UTC
  • Revision ID: james.westby@ubuntu.com-20100413223224-jduxnd0xxnkkda02
Tags: upstream-0018+dfsg
ImportĀ upstreamĀ versionĀ 0018+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 2 Jul 2009
 
17
 by Tom Igoe 
 
18
 
 
19
 http://www.arduino.cc/en/Tutorial/MIDI
 
20
 
 
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 (intnote = 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
 
41
//  cmd is greater than 127, or that data values are  less than 127:
 
42
void noteOn(int cmd, int pitch, int velocity) {
 
43
  Serial.print(cmd, BYTE);
 
44
  Serial.print(pitch, BYTE);
 
45
  Serial.print(velocity, BYTE);
 
46
}
 
47