 {
   // Main loop
   // 5 ports, from 0 to 4
-  for (int i = 0; i < 5; i++) {
+  for (int i = 0; i <= LASTPORT; i++) {
     if(analogRead(i) > THRESHOLD) {
       // Beam has been cut
       // i+1 is because i is 0 indexed, but the ID starts with 1

void musicOn(int ID) {
  switch (ID) {
  case 1:
    noteOn(0x90, note1, 0x7F);
    break;
  case 2:
    noteOn(0x90, note2, 0x7F);
    break;
  case 3:
    noteOn(0x90, note3, 0x7F);
    break;
  case 4:
    noteOn(0x90, note4, 0x7F);
    break;
  case 5:
    noteOn(0x90, note5, 0x7F);
    break;
  case 6:
    noteOn(0x90, note6, 0x7F);
    break;
  case 7:
    noteOn(0x90, note7, 0x7F);
    break;
  case 8:
    noteOn(0x90, note8, 0x7F);
    break;
  default:
    noteOn(0x80, note1, 0x00);
    break;
  }
}

  // Set instrument to trumpet
  // 0xC0 is the change instrument command
  // 0x39 is the instrument ID in hex
  Serial.write(CHANGEINSTRUMENT);
  Serial.write(0x39);
}

