       last_mem[buttons] = millis();
     }
   }
-  
+}
+
+void setup() {
+  lcd.begin(16,2);
+  strcpy(statusLine,"5R8SV SIG GEN");
+  update_status();
+  
+  // Set up DDS
+  pinMode(FQ_UD, OUTPUT);
+  pinMode(W_CLK, OUTPUT);
+  pinMode(DATAPIN, OUTPUT);
+  pinMode(RESET, OUTPUT);
+  
+  
+  // Set up Rotary Encoder
+  pinMode(A_PIN, INPUT_PULLUP);
+  pinMode(B_PIN, INPUT_PULLUP);
+  attachInterrupt(0, evaluateRotary, CHANGE);
+  attachInterrupt(1, evaluateRotary, CHANGE);
+  pinMode(RotEncSwPin, INPUT_PULLUP);
+  
+  // Set up Output Monitoring
+  pinMode(WARN_LED, OUTPUT);
+  digitalWrite(WARN_LED, LOW);
+  analogReference(INTERNAL);
+  threshold = 1023L * THRESHOLD_VOLTAGE / 1100;
+  
+  // Set up memory buttons
+  for (int buttons=0; buttons < NUMBER_MEM_BUTTONS; buttons++) {
+    pinMode(MEM_BUTTON_START_PIN + buttons,INPUT_PULLUP);  
+  }
+    
+ // start on M1 freq
+  EEPROM.get(eeAddressStart,freq);
+  if(freq < bandStart || freq > bandEnd) {
+    freq = bandInit;
+    EEPROM.put(eeAddressStart,freq);
+  }
+  
+ // start up the DDS... 
+  pulseHigh(RESET);
+  pulseHigh(W_CLK);
+  pulseHigh(FQ_UD); 
+  // start the oscillator...
+  send_frequency(freq);     
+  display_frequency(freq);
+}
+
+void loop() {
+  int freqCursorPosition = 4;
+  
+  // change freq dependent on rotary encoder spin direction
+  if(spinDirection != 0) {
+    if (spinDirection == 1) {
+      freq=constrain(freq-freqDelta,bandStart,bandEnd);
+    } else {
+      freq=constrain(freq+freqDelta,bandStart,bandEnd);
+    }
+    spinDirection = 0;
+    display_frequency(freq); // push the frequency to LCD display
+    send_frequency(freq);  // set the DDS to the new frequency  
+  }
+  
+  // check for the click of the rotary encoder 
+  if (!digitalRead(RotEncSwPin) && millis() - lastClick > 200) { // push button debounce
+    // if user clicks rotary encoder, change the size of the increment
+    if (freqDelta == 10) {
+      freqDelta = 1000000;
+    } else {
+      freqDelta /= 10;
+    }
+    lastClick = millis();
+  }
+  
+  //blink the cursor to show selected frequency resolution
+  if (millis() - lastBlink > 300) {
+    freqCursorPosition = 8;
+    for (long tempDelta = 10; tempDelta/freqDelta != 1; tempDelta *= 10) {
+      freqCursorPosition--;
+      if (freqCursorPosition == 2 || freqCursorPosition == 6) {  //hop the punctuation
+        freqCursorPosition--;
+      }
+    }
+    lcd.setCursor(freqCursorPosition,0);
+    if(blinkState) {
+      lcd.noBlink();
+    } else {
+      lcd.blink();
+    }
+    blinkState = !blinkState;
+    lastBlink = millis();
+  }
+  
+
+  handleMemoryButtons();
   checkOutputLevel();
   wipeStaleStatus();
 }

long lastClick = 0;
long lastBlink = 0;
long lastStatus = 0;
long last_mem[NUMBER_MEM_BUTTONS];

boolean blinkState = false;
boolean statusDisplayed = false;
boolean mem_armed[NUMBER_MEM_BUTTONS];

int eeAddressStart = 0;
int threshold = 0;

  }
}

//Handle Memory Button Pushes
void handleMemoryButtons() {

  static boolean mem_armed[NUMBER_MEM_BUTTONS];
  static long last_mem[NUMBER_MEM_BUTTONS];
  
  for (int buttons = 0; buttons < NUMBER_MEM_BUTTONS; buttons++) {   
    if(!mem_armed[buttons] && !digitalRead(MEM_BUTTON_START_PIN+buttons) && millis() - last_mem[buttons] > 50) {
      last_mem[buttons] = millis();
      mem_armed[buttons] = true;
