From bd36cfed2d0388317d0d90ad0e0d8cbff921be43 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Mon, 31 Dec 2018 18:07:20 +0100 Subject: [PATCH] read ADC in one step and adjust calculation (most probably it doesn't make much of a difference) --- libraries/Tiny/TinySensor.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libraries/Tiny/TinySensor.h b/libraries/Tiny/TinySensor.h index 5ee503d..048d7e0 100644 --- a/libraries/Tiny/TinySensor.h +++ b/libraries/Tiny/TinySensor.h @@ -35,15 +35,11 @@ protected: delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion - while (bit_is_set(ADCSRA, ADSC)) - ; // measuring + while (bit_is_set(ADCSRA, ADSC)); // measuring - uint8_t low = ADCL; // must read ADCL first - it then locks ADCH - uint8_t high = ADCH; // unlocks both + uint16_t result = ADC; // read ADC in one step - long result = (high << 8) | low; - - result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 + result = 1126400L / result; // Calculate Vcc (in mV); 1126400 = 1.1*1024*1000 return result; // Vcc in millivolts }