Hardware Reference
In-Depth Information
loop() cycles through all the
instruments in the bank. For each
instrument, it performs a MIDI
Program change to select the instru-
ment; then, it cycles through each of
the 16 channels. For each channel, it
plays notes from 21 (A0, the lowest
note on an 88-key piano) to 109 (C8,
the highest note).
8
void loop() {
//Cycle through all the instruments in the bank:
for(int instrument = 0 ; instrument < 127 ; instrument++) {
Serial.print(" Instrument: ");
Serial.println(instrument + 1);
// Program select. Has only one status byte:
sendMidi(0xC0, instrument, 0);
// change channels within the instrument:
for (int thisChannel = 0; thisChannel < 16; thisChannel++) {
Serial.print("Channel: ") ;
Serial.println(thisChannel + 1);
for (int thisNote = 21; thisNote < 109; thisNote++) {
// note on
noteOn(thisChannel, thisNote, 127);
delay(30);
// note off
noteOff(thisChannel, thisNote, 0);
delay(30);
}
}
}
}
noteOn() , noteOff() , and sendMidi()
are methods to send MIDI
commands. The sendMidi() method
just sends the three bytes you give it.
The noteOn() and noteOff() methods
use a bitwise OR operation to combine
the command (0x80 or 0x90) with the
channel into a single byte.
8
//Send a MIDI note-on message. Like pressing a piano key
//channel ranges from 0-15
void noteOn(byte channel, byte note, byte velocity) {
sendMidi( (0x90 | channel), note, velocity);
}
//Send a MIDI note-off message. Like releasing a piano key
void noteOff(byte channel, byte note, byte velocity) {
sendMidi( (0x80 | channel), note, velocity);
}
void sendMidi(int cmd, int data1, int data2) {
midi.write(cmd);
midi.write(data1);
midi.write(data2);
}
When you run this sketch, you should
hear all the sounds your synth can
make on the first bank of sounds.
 
Search WWH ::




Custom Search