   }
 }
 
-int color;
+int color = 99;
+int prevColor = 99;
+bool continuousNote = true;
+int sameColorCount = 0;
 
 void loop() {
   color = get_colors();
+  Serial.println(color);
+  if(prevColor == color){
+    continuousNote = true;
+    sameColorCount += 1;
+  }
+  else{
+    continuousNote = false;
+    sameColorCount = 0;
+  }
+  prevColor = color; 
 
   buttonStateSharp = digitalRead(buttonPinSharp);
   buttonStateFlat = digitalRead(buttonPinFlat);
   if (buttonStateSharp == LOW) {
     // turn LED on:
-    Serial.println("flat");
     color_to_note_flat(color);
   } 
   else if(buttonStateFlat == LOW) {
-    Serial.println("sharp");
     color_to_note_sharp(color);
   }
   else{
     // turn LED off:
-    Serial.println("normal");
     color_to_note_normal(color);
   }
-  delay(500);
+  delay(400);
 }
 
 int get_colors(){

void color_to_note_sharp(int c){
  switch(c){
  case 0:
    playNote("C#", octave, 300);
    break;
  case 1:
    playNote("D#", octave, 300);
    break;
  case 2:
    playNote("F", octave, 300);
    break;
  case 3: 
    playNote("F#", octave, 300);
    break;
  case 4:
    playNote("G#", octave, 300);
    break;
  case 5:
    playNote("A#", octave, 300);
    break;
  case 6:
    playNote("C", octave + 1, 300);   
    break;
  }
}


      index = i;
    }
  }
  
//  noteOn(0, index+octave*12, 64);
//  MIDIUSB.flush();
  
  if(continuousNote == false){
    Serial.println("note off");
    noteOff(0, index+octave*12, 64);
    MIDIUSB.flush();
  }
  
  delay(t);
  if(sameColorCount == 0){
    noteOn(0, index+octave*12, 64);
    MIDIUSB.flush();
  }
}

int octave = 4;
void color_to_note_normal(int c) {
  switch(c){
  case 0:
    playNote("C", octave, 400);
    break;
  case 1:
    playNote("D", octave, 400);
    break;
  case 2:
    playNote("E", octave, 400);
    break;
  case 3: 
    playNote("F", octave, 400);
    break;
  case 4:
    playNote("G", octave, 400);
    break;
  case 5:
    playNote("A", octave, 400);
    break;
  case 6:
    playNote("B", octave, 400);   
    break;
  default:
    Serial.println("note off");
    noteOff(0, index+octave*12, 64);
    MIDIUSB.flush();
  }
}

