   digitalWrite(LATCH, LOW);
 }
 
-bool getRomName() {
-  File config = SD.open("config.txt");
-  if (config) {
-    for (byte i = 0; config.peek() != '\n' && i <= FILENAME_SIZE; ++i) {
-      romName[i] = config.read();
-    }
-    config.close();
-    return true;
-  } else {
-    // File config.txt was not found or could not be opened.
-    return false;
-  }
+byte getKey(int pin) {
+  int v = analogRead(pin);
+  delay(50);
+  v = analogRead(pin);
+  if (v < 600 && v > 300)
+    return DOWNKEY;
+  if (v < 300 && v > 100)
+    return SELECTKEY;
+  if (v < 100)
+    return UPKEY;
+  return NOKEY;
 }

  pinMode(OEVCBUS, OUTPUT);
  pinMode(LED, OUTPUT);

  disableVCBus();

  // Initializing SD card and open ROM file
  if (SD.begin(SD_CS)) {
    if (getRomName()) {
      romFile = SD.open(romName);
    } else {
      // ROM name could not be determined.
      blinkTimeHigh = 50;
      blinkTimeLow = 500;
    }
  } else {
    // SD card not found or otherwise failing SD initialization.
    blinkTimeHigh = 50;
    blinkTimeLow  = 50;
  }

  // Write ROM file to SRAM
  if (romFile) {
    unsigned romSize = static_cast<unsigned>(romFile.size());
    if (romSize <= MAX_ROM_SIZE) {
      for (unsigned i = 0; i < romSize; i++) {
        write2RAM(i, romFile.read());
      }
    } else {
      // ROM size too big.
      blinkTimeHigh = 50;
      blinkTimeLow = 1000;
    }
    romFile.close();
    enableVCBus();
  } else {
    // ROM file could not be opened.
    blinkTimeHigh = 50;
    blinkTimeLow = 200;
  }
  SPI.end();  // Otherwise on-board LED does not work!
}

#include <SD.h>
#include <SPI.h>            // Needed for SD lib
#include <TM1637Display.h>  // 7-segment driver lib

// Defines for Arduino port numbers
#define CLOCK          5  // SRCLK (A/D-Bus Shift Registers)
#define LATCH          3  // RCLK  (A/D-Bus Shift Registers)
#define DATA           6  // SER   (A/D-Bus Shift Registers)
#define OESHIFT        2  // _G    (A/D-Bus Shift Registers)
#define WESRAM        10
#define OEVCBUS        7  // OE for Bus Transceivers
#define SD_CS          4  // Chip Select for SD card
#define DISPLAY_CLK   A4  // 7-segment display
#define DISPLAY_DIO   A5  // 7-segment display
#define LED           13

// Miscellaneous other defines
#define NOKEY           0
#define UPKEY           1
#define DOWNKEY         2
#define SELECTKEY       3
#define MAX_ROMS       99
#define MAX_ROM_SIZE 6144

// Global variables
byte lastkey = NOKEY;
byte romNumber = 1;
char romName[] = { 0, 0, 0, 0, 0, 0, 0 };
File romFile;
unsigned blinkTimeHigh = 500;
unsigned blinkTimeLow  = 500;
TM1637Display display(DISPLAY_CLK, DISPLAY_DIO);

void setup() {
  pinMode(SD_CS, OUTPUT);
