#include #include // for debug only, leave commented out for measuring current #define DEBUG // this method is called on the loop() thread void handle_ADC_result(int count) { #ifdef DEBUG Serial.print("ADC result "); Serial.print((count * 3.0) / 1023); Serial.println("V "); #endif // start again immediately uint32_t err = lp_ADC_start(31, handle_ADC_result); // pin 31 on BareBoard nRF52832, see lp_ADC.h file #ifdef DEBUG if (err != 0) { // if err != 0 then either arg error or busy err == 17 => busy if (err == 17) { // NRF_ERROR_BUSY) { Serial.println("adcBusy"); } else { Serial.print("adc argument error:"); Serial.println(err); } } #endif } void setup() { // using default Serial Tx=29, Rx=30 pins #ifdef DEBUG Serial.begin(115200); for (int i = 10; i > 0; i--) { Serial.print(i); Serial.print(' '); delay(500); } Serial.println(); #endif lp_ADC_calibrate(); // do a calibration before the first sample, add a timer to re-calibrate every min or so to allow for temperature changes. uint32_t err = lp_ADC_start(31, handle_ADC_result); // pin P0.31 on BareBoard nRF52832, see lp_ADC.h file } void loop() { // put your main code here, to run repeatedly: sleep(); #ifdef DEBUG // Serial.println("loop Woke up"); #endif }