File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed
Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -19,14 +19,21 @@ void ThinknodeM2Board::begin() {
1919 enterDeepSleep (0 );
2020 }
2121
22- uint16_t ThinknodeM2Board::getBattMilliVolts () {
22+ uint16_t ThinknodeM2Board::getBattMilliVolts () {
2323 analogReadResolution (12 );
24- delay (10 );
25- float volts = (analogRead (PIN_VBAT_READ) * ADC_MULTIPLIER * AREF_VOLTAGE) / 4096 ;
26- analogReadResolution (10 );
27- return volts * 1000 ;
28- }
24+ analogSetPinAttenuation (PIN_VBAT_READ, ADC_11db);
25+
26+ uint32_t mv = 0 ;
27+ for (int i = 0 ; i < 8 ; ++i) {
28+ mv += analogReadMilliVolts (PIN_VBAT_READ);
29+ delayMicroseconds (200 );
30+ }
31+ mv /= 8 ;
32+
33+ analogReadResolution (10 );
34+ return static_cast <uint16_t >(mv * ADC_MULTIPLIER );
35+ }
2936
3037 const char * ThinknodeM2Board::getManufacturerName () const {
3138 return " Elecrow ThinkNode M2" ;
32- }
39+ }
You can’t perform that action at this time.
0 commit comments