   // 130: audible 
   // 254: min volume
   // 255: analog off
-  player.setVolume(64, 64);
+  player.setVolume(volume, volume);
+}
+
+void initializeTrellis(int delay) {
+  trellis.begin(0x70);
+  //trellis.readSwitches(); // ignore already pressed switches
+  Serial.println("Trellis initialized");
+
+  trellis.blinkRate(HT16K33_BLINK_OFF);
+  trellis.clear();
+  trellis.writeDisplay();
+
+  nextIdleTick = millis() + delay;
+}
+
+void initializeTimer() {
+  Timer1.initialize(1000);
+  Timer1.attachInterrupt(timerIsr); 
+  Serial.println("Timer initialized");
+}
+
+/*************************************************** 
+ * Interrupt-Handler
+ ****************************************************/
+void timerIsr() {
+  encoder.service();
+}
+
+/*************************************************** 
+ * Loop
+ ****************************************************/
+void loop() {
+  unsigned long now = millis();
+
+  // Rollover millis since start
+  if (nextReadTick > now + (1000L * 60L * 60L)) {
+    Serial.println("Rollover timer ticks!");
+    nextReadTick = now;
+    nextIdleTick = now;
+  }
+
+  // Next ticks
+  if (nextReadTick <= now) {
+    nextReadTick += tickReadKeys();
+  }
+  if (nextIdleTick <= now) {
+    nextIdleTick += tickIdleShow();
+  }
 }
 
 unsigned int tickIdleShow() {

byte nextLED = 0;
byte playingAlbum;
File album;


/*************************************************** 

  Arduino control code for a music maker board and a trellis keypad.

  The control code shall
   * read trellis keys (/)
   * on key press play a music file from the micro SD card from a specific folder and blink the respective key (/)
   * on pressing the same key or when playback stops jump to the next file in the folder, until all music is played (/)
   * read the rotary decoder to change the volume, the maximum volume can be configured
   * detect when a headphone is plugged in and mute the amplifier for the internal speakers
   * switch the music box off automatically after an idle period

  Todos:
   - Serial waits for a max. time
   - Audio off when idle (volume 255,255)

  Written by Jörg Keller, Switzerland  
  MIT license, all text above must be included in any redistribution
