   return Serial.read();
 }
 
-void serialTX(byte oB) // for testing purposes only
+float sensV() // measure the AverageValue
 {
-  if (oB == 13)
-  {
-    Serial.write(11);
-  }
-  Serial.write(oB);
-}
-
-float sensV() // measure the voltage
-{
-  float voltage = 0.0;        // result
-  int sumSamples = 0;         // sum of samplevalues
-  int cntSamples = 0;         // sample counter
+  float AverageValue = 0.0;        // result
+  int SumSamples = 0;         // sum of samplevalues
+  int CountSamples = 0;         // sample counter
 
   // *** Add up the pre-defined number of samples for Sample Averaging
-  for (cntSamples = 0; cntSamples <= numSamples; cntSamples++)
+  for (CountSamples = 0; CountSamples <= NUM_SAMPLES; CountSamples++)
   {
-    sumSamples += analogRead(measurePin);
+    SumSamples += analogRead(VoltMeasurePIN);
     delay(10);
   }
 
-  // *** Determine the source voltage:
-  voltage = (float)sumSamples / (float)numSamples; // Calculate avg raw value.
-  voltage *= scaleRaw2Volts;      // Scale avg raw value to source voltage.
-  return voltage;
+  // *** Determine the source AverageValue:
+  AverageValue = (float)SumSamples / (float)NUM_SAMPLES; // Calculate avg raw value.
+  AverageValue *= SCALE_RAW_TO_VOLTS;      // Scale avg raw value to source AverageValue.
+  return AverageValue;
 
 }
 

*/

// +V from battery is connected to analog pin 0
#define measurePin A0
#define activityLED 13

// *** declare constants
const float ref5V = 5.14;   // reference: 5.0V on measurePin == 1023.0
const float R1 = 100000.0;  // Resistor value used for R1
const float R2 = 10000.0;   // Resistor value used for R2

// (numSamples ^ 0.5) is the S/N ratio that can be achieved.
// To get a S/N-ratio of 3 requires 9 samples. S/N=4 requires 16 samples
// More samples means longer measurement times.
// Beware, numSamples * 1024 should not exceed the positive maximum for the
// `int` data-type!
// Therefore the maximum numSamples = (32767 / 1023 = ) 32
const int numSamples = 16;  // number of measurements used for one result

// *** declare calculated constants
const float ratioRes = (R2/(R1 + R2));
const float scaleRaw2Volts = ref5V / (ratioRes * 1023.0);

// *** declare variables
unsigned long startTime;
unsigned long elapsedTime;
float retValue = 0.0;
byte cmd;

void setup()
{
  pinMode(activityLED, OUTPUT);   // An LED to signal activity
  Serial.begin(9600);             // Initialise serial port
}


{
  if (Serial.available() > 0)
  {
    digitalWrite(ActivityLED, HIGH);  // signal activity detected

    ActionRequest = serialRX();                 // See what the input is

    Serial.print((char)ActionRequest);          // Signal start of telegram
    Serial.print(" ");                // Delimiter
    switch (ActionRequest)
    {
      case 'V':
      case 'v':
        ReturnedValue = sensV();
        Serial.print(ReturnedValue);        // AverageValue
        break;
      default:
        Serial.print("NaN");          // Invalid ActionRequest returns `NaN`
    }
    Serial.println(" !");             // Signal end of telegram

    digitalWrite(ActivityLED, LOW);   // end of activity
  }
}
