 const float scaleRaw2Volts = ref5V / (ratioRes * 1023.0);
 
 // *** declare variables
-int sumSamples = 0;         // sum of samples
-int cntSamples = 0;         // sample counter
-float voltage = 0.0;
 unsigned long startTime;
 unsigned long elapsedTime;
-byte cmd = 0;
+float retValue = 0.0;
+byte cmd;
 
 void setup()
 {


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

    Serial.print(cmd);                // Signal start of telegram
    Serial.print(" ");                // Delimiter
    switch (cmd)
    {
      case 'V':
        voltage = sensV();
        Serial.print(voltage);        // Voltage
        break;
      default:
        Serial.print("NaN");          // Invalid cmd returns `NaN`


float sensV() // measure the voltage
{
  float voltage = 0.0;        // result
  int sumSamples = 0;         // sum of samplevalues
  int cntSamples = 0;         // sample counter

  // *** Add up the pre-defined number of samples for Sample Averaging
  for (cntSamples = 0; cntSamples <= numSamples; cntSamples++)
