   keypad.addEventListener(keypadEvent);             //add an event listener for this keypad
 }
 
+void SetFrequencyStage1() {
+	// STAGE 1 tuning process
+	calculateC();                                     // calculate C value at selected frequency
+	calculateStepsC();                                // calculate steps needed to move C to value C
+	CmoveStage1();                                    // send command to nano to move motor "C" to C step value
+	calculateL();                                     // calculate L value at given frequency and C value
+	calculateStepsL();                                // calculate steps needed to move C to value L
+	LmoveStage1();                                    // send command to nano to move motor "L" to L step value
+	EraseDisplayC(), EraseDisplayL();                 // clear previous values L and C at display
+	displayC(), displayL();                           // display current values L and C at display
+	tuningDisplay();                                  // flashing tuning - this to be changed to start at CmoveStage1 and finish after LmoveStage1
+	displayTunedFreqTopScreen();                      // emulation of Green Tuned after motors in place
+	mechSetPosition(round (valueRotateL), round (valueRotateC));
+	// End STAGE 1 tuning process
+}
+
 void SetFrequency() {                               // when # pressed - sets frequency value at the top of the screen
-
   // Pre-STAGE 1 (coarse tuning process) cleanups and displays
   eraseFreqTopScreen();                             // clear previously entered drequesncy at display top
   displayFreqTopScreen();                           // display desired frequesncy at display top
   eraseEnteredFrequency();                          // clear entered frequency at display bottom
- 
-  // STAGE 1 tuning process
-  calculateC();                                     // calculate C value at selected frequency
-  calculateStepsC();                                // calculate steps needed to move C to value C
-  CmoveStage1();                                    // send command to nano to move motor "C" to C step value
-  calculateL();                                     // calculate L value at given frequency and C value
-  calculateStepsL();                                // calculate steps needed to move C to value L
-  LmoveStage1();                                    // send command to nano to move motor "L" to L step value
-  EraseDisplayC(), EraseDisplayL();                 // clear previous values L and C at display
-  displayC(), displayL();                           // display current values L and C at display
-  tuningDisplay();                                  // flashing tuning - this to be changed to start at CmoveStage1 and finish after LmoveStage1
-  displayTunedFreqTopScreen();                      // emulation of Green Tuned after motors in place
-  mechSetPosition(round (valueRotateL), round (valueRotateC));
-  // End STAGE 1 tuning process
-}
+  SetFrequencyStage1();
+}
+
 
 void incL(float diff) {
 	valueRotateL = valueRotateL + diff;

  KHz = 1000;
  PlanckTime = 299792458;
  Cmult = 1.5;
  valueC = PlanckTime / ( tuningFreqCalc * KHz ) * Cmult;
  Serial.print("Value C pF=");
  Serial.println(valueC);
}

void calculateL () {                            // Calculate "L" value from formula L=((1/(2*π*f*C))/(2*π*f))*1000000000000 (where f in KHz and C in pF)
  pi = 3.14159;
  Lmult = 1000000000000;
  valueL = ((1 / (2 * pi * tuningFreqCalc * valueC)) / (2 * pi * tuningFreqCalc)) * Lmult + valueLcorr;
  Serial.print("Value L uH=");
  Serial.println(valueL);
}
