 #define CONNECT_WAIT_MILLIS 10000
 #define LOW_THRESHOLD 12000 // milliVolts
 #define ADC_SAMPLES 20
+#define ADC_DISPERSED 2
 #define SLEEP_SECS 3600 // 1 hour
 //#define SLEEP_SECS 15
 


void publishVoltageEvent() {
    char eventData[5];
    uint16_t milliVolts = getAvgBatteryMilliVolts();
    sprintf(eventData, "%.1f", milliVolts / 1000.0);
    if (milliVolts < LOW_THRESHOLD) {
        Particle.publish(LOW_EVENT, eventData, 60, PRIVATE);

    flashing = true;
}

// Averaging of N-X ADC samples as per ST Application Note AN4073
uint16_t getCentralAvgBatteryMilliVolts() {
    uint32_t mV = 0;
    uint16_t readings[ADC_SAMPLES];

    for (int i = 0; i < ADC_SAMPLES; i++) {
        readings[i] = readMilliVolts(BATTERY_PIN);
        delay(3);
    }

    qsort(readings, ADC_SAMPLES, sizeof(uint16_t), uint16Compare);

    for (int i = ADC_DISPERSED; i < ADC_SAMPLES - ADC_DISPERSED; i++) {
        mV += readings[i];
    }

    return round(mV * DIV_RATIO / (float) ADC_SAMPLES - (2 * ADC_DISPERSED));
}

// Averaging of N ADC samples as per ST Application Note AN4073
uint16_t getAvgBatteryMilliVolts() {
    uint32_t mV = 0;
    for (int i = 0; i < ADC_SAMPLES; i++) {
        mV += readMilliVolts(BATTERY_PIN);
        delay(3);
