 
 void loop() {
   
-  // 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();
-  }
-  
+  wasRotaryEncoderSpun();
+  wasRotaryEncoderClicked();
   blinkCursor();
   handleMemoryButtons();
   checkOutputLevel();
   wipeStaleStatus();
-}
+  
+}

  } 
}

void checkOutputLevel() {
  static long lastTrigger = 0;
  

#define MEM_BUTTON_START_PIN  10  // digital pin where mem buttons start
#define NUMBER_MEM_BUTTONS    2  // how many mem buttons

#define EE_ADDRESS_START      0

const double bandStart = 100000;  // start of Gnerator at 100 KHZ
const double bandEnd = 40000000; // End of Generator at 40 MHz --signal will be a bit flaky!
const double bandInit = 7150000; // where to initially set the frequency for tetsting Part II

double freq = 0 ;  // tuning frequency in Hz
double freqDelta = 10000; // how much to change the frequency by, clicking the rotary encoder will change this.

byte spinDirection = 0; // rotary encoder spun ccw (-1), cw (1), or no change (0)

long lastStatus = 0;
boolean statusDisplayed = false;
char statusLine[21];

int threshold = 0; 

// Connect via i2c, default address #1 (nothing jumpered)
Adafruit_LiquidCrystal lcd(0);
