 struct MenuItem *mia_main[] = {&mi_slots, &mi_settings, &mi_reset, &mi_credits};
 struct Menu menu_main = {"Menu", ALEN(mia_main), mia_main};
 
-
-//----------------------------------------
-// Standard Arduino loop() function.
-//----------------------------------------
-
-void loop(void)
-{
-#if INC_BATTERY
-  // measure voltage every whenever
-  // we will get a value of 1023 for 3.3 volts
-  static UINT last_volts_time = -VoltageDelay;    // millis() value last time we measured
-  ULONG now = millis();
-  if (now < last_volts_time)
-    last_volts_time = -VoltageDelay;    // handle wraparound of millis()
-  if (now > last_volts_time + VoltageDelay)
-  {
-    last_volts_time = now;
-    UINT measured = analogRead(mc_BattVolts);
-    MeasuredVoltage = ((3.3 * measured) / 1023) * (32.0/10.0);
+//----------------------------------------
+// Measure the battery voltage.
+// We measure every "MeasureVoltageDelay" milliseconds, update the battery symbol.
+// If DEBUG reporting is turned on, we report every "ReportVoltageDelay" measurements.
+//----------------------------------------
+
+void measure_battery(void)
+{
+  // get the time since the last measurement
+  static long last_volts_time = -MeasureVoltageDelay;    // millis() value last time we measured
+  long now_milli = millis();
+  if (now_milli < last_volts_time)
+    last_volts_time = -MeasureVoltageDelay;    // handle wraparound of millis()
+
+  // if not time yet, return
+  if (now_milli < last_volts_time + MeasureVoltageDelay)
+    return;
+
+  // measuring, set measurement time to "now"
+  last_volts_time = now_milli;
+      
+  // measure voltage, we will get a value of 1023 for 3.3 volts
+  UINT measured = analogRead(mc_BattVolts);
+  MeasuredVoltage = ((3.3 * measured) / 1023) * (32.0/10.0);
 
 #if (DEBUG & DEBUG_BATT)
-      Serial.printf(F("raw volts=%d\n"), measured);
-#endif
-
-    // figure out which battery symbol to use
-    if (MeasuredVoltage < MinVoltage)
+  static int batt_report_count = 0;
+  if (++batt_report_count > 0)
+  {
+    Serial.printf(F("raw volts=%d, "), measured);
+  }
+#endif
+
+  // figure out which battery symbol to use
+  if (MeasuredVoltage < MinVoltage)
+  {
+    if (MeasuredVoltage < 1.0)
     {
-        BatterySymbol = battunder;
-        if (MeasuredVoltage < 1.0)
-        {
-          BatterySymbol = battnone;
-        }
+      BatterySymbol = battnone;
+#if (DEBUG & DEBUG_BATT)
+      if (batt_report_count > 0)
+        Serial.printf(F("no battery\n"));
+#endif      
     }
-    else if (MeasuredVoltage > MaxVoltage)
-        BatterySymbol = battover;
     else
     {
-      int percent = (int) ((MeasuredVoltage - MinVoltage) / (MaxVoltage - MinVoltage) * 100.0);
-      int batt_bucket = (int) (percent/20);
-      BatterySymbol = batt_syms[batt_bucket + 2];
+      BatterySymbol = battunder;
 #if (DEBUG & DEBUG_BATT)
+      if (batt_report_count > 0)
+        Serial.printf(F("battery under voltage\n"));
+#endif      
+    }
+  }
+  else if (MeasuredVoltage > MaxVoltage)
+  {
+    BatterySymbol = battover;
+#if (DEBUG & DEBUG_BATT)
+    if (batt_report_count > 0)
+      Serial.printf(F("battery over voltage\n"));
+#endif      
+  }
+  else
+  {
+    int percent = (int) ((MeasuredVoltage - MinVoltage) / (MaxVoltage - MinVoltage) * 100.0);
+    int batt_bucket = (int) (percent/20);
+    BatterySymbol = batt_syms[batt_bucket + 2];
+#if (DEBUG & DEBUG_BATT)
+    if (batt_report_count > 0)
+    {
       Serial.printf(F("actual volts=%f, percent=%d, batt_bucket=%d\n"),
                       MeasuredVoltage, percent, batt_bucket);
-#endif
+      batt_report_count = -ReportVoltageDelay;
     }
-    display_battery();
-  }
-#endif
-
-  // gather any commands from controller
+#endif
+  }
+}
+
+//----------------------------------------
+// Do any commands from the external controller.
+//----------------------------------------
+
+void do_external_commands(void)
+{
+  // gather any commands from the external controller
   while (Serial.available()) 
   {
     char ch = Serial.read();

{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Vfo:");
  display_sel_value(VfoFrequency, VfoSelectDigit, NumFreqChars, NumCols - NumFreqChars - 2, 0);
  lcd.print("Hz");


#include <LiquidCrystal.h>
#include <EEPROM.h>

// debug bit masks:
#define DEBUG_DDS     (1 << 0)
#define DEBUG_FREQ    (1 << 1)
