To MidiLibrary or not to MidiLibrary - That is the question!!

Okay, I'm now the new kid on the block and quickly getting frustrated, I guess!! Now, I realize that I've happened to buy an Uno version 1.0!! Since the Arduino Midilibrary that Franky wrote requires version 13 or better (not sure if that was supposed to be version 3), I guess that's why I'm not able to use the header: #include <MIDI.h> . I always get compile errors saying that it can't find some file (WConstants.h???).

Can someone give me a very simple way to change the voice or sound library in the following sketch? I have been searching for something that I can understand as an example to modify and just see what happens but I can't seem to adapt anything to move out of the Grand Piano voice in the following example. Please, help... even if just a little!

/*
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://www.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 < 0x5A; note ++) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
delay(100);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
delay(100);
}
}

// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}

There's two versions in play - the hardware version (1,2,3 the latest) and then there's the version of IDE that runs on your PC.
The IDE was up to -0023 until recently, when it went to version 1.
If the version 1 IDE is not working for the -0013 library above, try going back to IDE version -0022 or 0023.

That was the issue!!!!!!! Cool, now I'm rolling again!!!!! :slight_smile: I think between that and some of the explanation on the Midi code library, I should be putting out some tunes from this little gizmo shortly!!! Thanks, so much. Hope I can pass on the help in a few more weeks to others!!

Just a short and extremely simple example for those that are struggling from the get go!

#include <MIDI.h>
/*
Midi Out Example
nc_it_guy

Example loops up the keyboard notes playing 3rds as it goes
then loops through the midi voices from 1 (Piano) through 127 (Applause)

*/

void setup() {
MIDI.begin(4); // Launch MIDI with default options
// input channel is set to 4
}

void loop() {
{
for (int pgm = 1; pgm < 127; pgm++) // Sets up for the voice loop
{
for (int note = 40; note < 90; note ++) // Sets up for the note loop
{
MIDI.sendNoteOn(note,45,1); // Send a Note (value of int note, velo 45 on channel 1)
MIDI.sendNoteOn(note+=3,45,1); // Setup and play the 3rd above (note+=3)

delay(100); // 1/10th of a second delay

MIDI.sendNoteOff(note-=3,0,1); // Stop the note (remember we added 3 earlier)
// Maybe not the best way but it works
MIDI.sendNoteOff(note+=3,0,1); // Stop the third above

MIDI.sendProgramChange(pgm,1); // Change the voice
}
}
}
}