MIDI Code Trouble

Hello, Arduino Forum;
I am having trouble with a laser harp project I am working on. I am using the MIDI code from http://arduino.cc/en/Tutorial/Midi but upon uploading I receive the message that "midilazerharpp:109: error: 'noteOn' was not declared in this scope" and many others like it. Here is my code, can someone help and let me know what I'm doing wrong?

void setup() {
// Set MIDI baud rate:
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(5,INPUT);
pinMode(6,INPUT);
pinMode(7,INPUT);
pinMode(8,INPUT);
pinMode(9,INPUT);
Serial.begin(31250);
int millis2 = 0;
int millis3 = 0;
int millis4 = 0;
int millis5 = 0;
int millis6 = 0;
int millis7 = 0;
int millis8 = 0;
int millis9 = 0;

}

void loop() {
while(true){

if(digitalRead(2) == LOW)
{
noteOn(0x90, 0x1E, 0x45);
millis2 = millis();
}

if(digitalRead(3) == LOW)
{
noteOn(0x91, 0x1F, 0x45);
millis3 = millis();
}

if(digitalRead(4) == LOW)
{
noteOn(0x92, 0x20, 0x45);
millis4 = millis();
}

if(digitalRead(5) == LOW)
{
noteOn(0x93, 0x21, 0x45);
millis5 = millis();
}

if(digitalRead(6) == LOW)
{
noteOn(0x94, 0x22, 0x45);
millis6 = millis();
}

if(digitalRead(7) == LOW)
{
noteOn(0x95, 0x23, 0x45);
millis7 = millis();
}

if(digitalRead(8) == LOW)
{
noteOn(0x96, 0x24, 0x45);
millis8 = millis();
}

if(digitalRead(9) == LOW)
{
noteOn(0x97, 0x25, 0x45);
millis9 = millis();
}

//Code above checks if the beam is broken.
//Code below checks if the time is done.

if(millis() - millis2 >= 500 && millis2 != 0)
{
noteOn(0x90, 0x1E, 0x00);
millis2 = 0;
}

if(millis() - millis3 >= 500 && millis3 != 0)
{
noteOn(0x91, 0x1F, 0x00);
millis3 = 0;
}

if(millis() - millis4 >= 500 && millis4 != 0)
{
noteOn(0x92, 0x20, 0x00);
millis4 = 0;
}

if(millis() - millis5 >= 500 && millis5 != 0)
{
noteOn(0x93, 0x21, 0x00);
millis5 = 0;
}

if(millis() - millis6 >= 500 && millis6 != 0)
{
noteOn(0x94, 0x22, 00);
millis6 = 0;
}

if(millis() - millis7 >= 500 && millis7 != 0)
{
noteOn(0x95, 0x23, 0x00);
millis7 = 0;
}

if(millis() - millis8 >= 500 && millis8 != 0)
{
noteOn(0x96, 0x24, 0x00);
millis8 = 0;
}

if(millis() - millis9 >= 500 && millis9 != 0)
{
noteOn(0x97, 0x25, 0x00);
millis9 = 0;
}

}
}

Check the error messages again and scroll up to the first error. I'll wager there will be something about "no such file or directory" in there. You probably haven't installed the library correctly.

Did you install and use the MIDI library?

Did you set the MIDI baud rate?

Thank you guys for your help. I did check, the MIDI baud rate is set in void setup, it looked like it wasn't because it was a few lines down from the comment about it. I moved it for easier visibility. As far as the MIDI library, which would make sense, the page I referenced doesn't say anything about needing a separate library to work. Is it assuming that I have some library installed before I start?

I've just spent about half an hour checking through the page you've linked to along with just about every link that it links to. I can't find any trace of any code that looks anything like the sketch you've posted here.

Looking through your code that's hardly surprising. I find faults with practically EVERY line in it. You really need to find an example and get to understand it.

You either need a MIDI library that contains the noteOn() function or you have to define the noteOn() function in your sketch.

//NO INCLUDE FILES UP HERE


void setup() {
  //  Set MIDI baud rate:  //This comment means nothing, you're not setting the baud rate here
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  pinMode(4,INPUT);
  pinMode(5,INPUT);
  pinMode(6,INPUT);
  pinMode(7,INPUT);
  pinMode(8,INPUT);
  pinMode(9,INPUT);
  Serial.begin(31250);    // At least you do set the baud rate here.
                          // But is your midi interface connected to pins 0 and 1
                          // I doubt it.

  int millis2 = 0;  // By declaring these variables within setup
  int millis3 = 0;  // They cease to exist as soon as setup() has completed
  int millis4 = 0;  // What's more, they're too small to hold millis.
  int millis5 = 0;  // They should be unsigned long
  int millis6 = 0;
  int millis7 = 0;
  int millis8 = 0;
  int millis9 = 0;

}

void loop() {
    while(true){                //Pointlessly preventing the loop looping so that you can loop!
     
    if(digitalRead(2) == LOW)
    {
    noteOn(0x90, 0x1E, 0x45);   // You can't do this here as you haven't included
                                // Any library that defines noteOn
    millis2 = millis();         // storing a value that doesn't fit 
                                // in a variable that doesn't even exist
    }
   
    if(digitalRead(3) == LOW)
    {
    noteOn(0x91, 0x1F, 0x45);   //Same as above
    millis3 = millis();         
    }
   
  //need I go on?

You can greatly simplify your code using arrays instead of separate variables for each input. This will allow you to expand your note range by adding more pins to the list of input pins. You can even chose something like pentatonic scales instead of consecutive notes because an array of note values can assign any note to any beam.

// Laser Harp
const int BeamPins[] = {
  2,3,4,5,6,7,8,9};
const int BeamCount = sizeof BeamPins / sizeof BeamPins[0];
unsigned long BeamBrokenTime[BeamCount];  // globals initialized to zero by default
const int BeamNotes[BeamCount] = {
  0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25};

void setup() {
  Serial.begin(31250); //  Set MIDI baud rate:
  for (int i=0; i<BeamCount; i++)
    pinMode(BeamPins[i],INPUT);
}

void loop() {
  // For each beam,
  for (int i=0; i<BeamCount; i++) {

    // Play the note if the beam is freshly broken
    if(digitalRead(BeamPins[i]) == LOW) {
      // Play the note if it is not already playing
      if (BeamBrokenTime[i] == 0)
        noteOn(0x90, BeamNotes[i], 0x45);
      BeamBrokenTime[i] = millis();
    }

    // Release the note if the beam has not been broken for half a second.
    if(millis() - BeamBrokenTime[i] >= 500 && BeamBrokenTime[i] != 0) {
      noteOn(0x90, BeamNotes[i], 0x00);
      BeamBrokenTime[i] = 0;
    }
  }
}

//  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);
}

OK, thank all of you, it turns out that the problem was that in the page I referenced, the noteOn function was at the very bottom and I didn't notice it. It works now. Thanks for deigning to help a newbie like me, I do appreciate it.