     // this should be ok
     value = adc->analogRead(pin_cmp, ADC_0);
     if(adc->adc0->fail_flag != ADC_ERROR::CLEAR) {
+      if (debug) {
         Serial.println("Some other error happened when comparison should have succeeded.");
         Serial.println(adc->adc0->getError());
+      }
         pass_test = false;
     }
 


#if defined(ADC_TEENSY_LC) // teensy LC
#define PINS 13
#define DIG_PINS 13
#define PINS_DIFF 2
uint8_t adc_pins[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8, A9,A10,A11, A12};
uint8_t adc_pins_dig[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8, A9,A10,A11, A12};
uint8_t adc_pins_diff[] = {A10, A11};

#elif defined(ADC_TEENSY_3_0)  // teensy 3.0
#define PINS 14
#define DIG_PINS 10
#define PINS_DIFF 4
uint8_t adc_pins[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13};
uint8_t adc_pins_dig[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8,A9};
uint8_t adc_pins_diff[] = {A10, A11, A12, A13};

#elif defined(ADC_TEENSY_3_1) || defined(ADC_TEENSY_3_2)  // teensy 3.1/3.2
#define PINS 21
#define DIG_PINS 16
#define PINS_DIFF 4
uint8_t adc_pins[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,
                      A14, A15,A16,A17,A18,A19,A20 };
uint8_t adc_pins_dig[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8,A9, A15,A16,A17,A18,A19,A20 };
uint8_t adc_pins_diff[] = {A10, A11, A12, A13};

#elif defined(ADC_TEENSY_3_5)  // Teensy 3.5
#define PINS 27
#define DIG_PINS 21
#define PINS_DIFF 2
uint8_t adc_pins[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8, A9, A10,
                      A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21,A22,A23,A24, A25, A26};
uint8_t adc_pins_dig[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8, A9, A12,A13,A14,A15,A16,A17,A18,A19,A20,A23,A24};
uint8_t adc_pins_diff[] = {A10, A11};

#elif defined(ADC_TEENSY_3_6)  // Teensy 3.6
#define PINS 25
#define DIG_PINS 21
#define PINS_DIFF 2
uint8_t adc_pins[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8, A9, A10,
                      A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21,A22,A23,A24};
uint8_t adc_pins_dig[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8, A9, A12,A13,A14,A15,A16,A17,A18,A19,A20,A23,A24};
uint8_t adc_pins_diff[] = {A10, A11};

#elif defined(ADC_TEENSY_4)  // Teensy 4
#define PINS 14
#define DIG_PINS 10
#define PINS_DIFF 0
uint8_t adc_pins[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8, A9, A10,
                      A11,A12,A13};
uint8_t adc_pins_dig[] = {A0,A1,A2,A3,A4,A5,A6,A7,A8, A9};
uint8_t adc_pins_diff[] = {};
#endif // defined


int value = 0;

// test the analog pins that also have a digital function
bool test_pullup_down(bool pullup) {
    uint8_t mode = pullup ? INPUT_PULLUP : INPUT_PULLDOWN;

    const int max_val = adc->getMaxValue(ADC_0);

    bool pass_test = true;

    for (int i=0;i<DIG_PINS;i++) {
        pinMode(adc_pins_dig[i], mode);
        delay(50); // settle time
        value = adc->analogRead(adc_pins_dig[i]);
        bool fail_condition = pullup ? (value < 0.95*max_val) : (value > 0.05*max_val);
        if (fail_condition) {
            Serial.print("A"); Serial.print(i); Serial.print(": ");
            Serial.print("FAILED "); Serial.print(pullup ? "INPUT_PULLUP" : "INPUT_PULLDOWN");
            Serial.print("("); Serial.print(value); Serial.print(")");
            Serial.println(". ");
            pass_test = false;
        }
    }

    return pass_test;
}

const uint8_t pin_cmp = A0;

bool test_compare() {
    bool pass_test = true;

    // measurement will be ready if value < 1.0V
    adc->enableCompare(1.0/3.3*adc->getMaxValue(ADC_0), 0, ADC_0);

    pinMode(pin_cmp, INPUT_PULLUP); // set to max
    // this should fail
    value = adc->analogRead(pin_cmp, ADC_0);
    if (adc->adc0->fail_flag != ADC_ERROR::COMPARISON) {
        Serial.println("Comparison didn't fail.");
        Serial.println(adc->adc0->getError());
        pass_test = false;
    }
    adc->adc0->resetError();

    pinMode(pin_cmp, INPUT_PULLDOWN); // set to min
    // this should be ok
    value = adc->analogRead(pin_cmp, ADC_0);
    if(adc->adc0->fail_flag != ADC_ERROR::CLEAR) {
        Serial.println("Some other error happened when comparison should have succeeded.");
        Serial.println(adc->adc0->getError());
        pass_test = false;
    }
    adc->adc0->resetError();

    return pass_test;
}

bool test_compare_range() {
    bool pass_test = true;

    // ready if value lies out of [1.0,2.0] V

    // this should be ok
    value = adc->analogRead(pin_cmp, ADC_0);
    if(adc->adc0->fail_flag != ADC_ERROR::CLEAR) {
      if (debug) {
        Serial.println("Some other error happened when comparison should have succeeded.");
        Serial.println(adc->adc0->getError());
      }
        pass_test = false;
    }
    adc->adc0->resetError();

    adc->adc0->disableCompare();

    return pass_test;
}


bool test_averages(bool debug=false) {
    elapsedMicros timeElapsed;
    bool pass_test = true;
    const uint8_t averages[] = {4, 8, 16, 32};
    float avg_times[4];
    volatile int value = 0;
