   acc_cnt = 0;
   acc_sum = 0;
   acc_max = 0;
+  acc_start = millis();
 }
 
 // update variables for raw noise measurments

#define CNT_MAX 2000

// number of samples used to calibrate min and max
#define CALIBRATION_SAMPLES 50

// size of diff histo for calibration
#define CALIBRATION_HISTO_SIZE 10

}

// update calibration of noise level differences
// assumtion is that most frequently observed difference 
// between max and min value represents silence.
void updateNoiseLevelCalibration() {

  // continuous sampling
  calibration_diff[calibration_cnt++ % CALIBRATION_SAMPLES] = val_max - val_min;
  
  if(calibration_cnt == CALIBRATION_SAMPLES) {
    calibration_cnt = 0;
  }
  
  // update histogram for calibration
  for (int i = 0; i < CALIBRATION_SAMPLES; i++) {
    if (calibration_diff[i] < CALIBRATION_HISTO_SIZE) {
      calibration_histo[calibration_diff[i]]++;
    }
  }

  // reset diff_min
  diff_min = 0;

  // find best diff_min.
  // assumpion: most frequent noise diff value represents silence
  for (int i = 1; i < CALIBRATION_HISTO_SIZE; i++) {
    if (calibration_histo[i] > calibration_histo[diff_min]) {
      diff_min = i;
    }
  }
}

// update variables for accumulated noise measurments
void updateNoiseLevelValues(int d) {
  if (diff > acc_max) {
    acc_max = d;
  }
