 void onKey(byte index) {
   if (state == PLAY_SELECTED && playingAlbum == index) {
     // Pressed playing key again
+    stopPlayingAlbum();
     Serial.print("Stopped album #"); Serial.println(index);
-    initializeTrellis(true);
+    initializeTrellis(1200);
   } else {
     // Pressed key to play a new album
+    if (state == PLAY_SELECTED) stopPlayingAlbum();
     trellis.clear();
     trellis.setLED(index);
     trellis.blinkRate(HT16K33_BLINK_1HZ);



Adafruit_Trellis trellis = Adafruit_Trellis();
unsigned long nextIdleTick = millis();
unsigned long nextReadTick = millis();
byte state = IDLE_LIGHT_UP;

  
    state = PLAY_SELECTED;
    playingAlbum = index;
    playAlbumNew(index);
   
    Serial.print("Playing album #"); Serial.println(index);
  }
}

void playAlbumNew(byte index) {
  switch (index) {
    case 0: player.startPlayingFile("track001.mp3"); break;
    case 1: player.startPlayingFile("track002.mp3"); break;
    case 2: player.startPlayingFile("track003.mp3"); break;
    case 3: player.sineTest(0x44, 500); break;
  }
}

void stopPlayingAlbum() {
  player.stopPlaying();
  delay(20);
}

