tweak getBattMilliVolts to report battery more accurately

This commit is contained in:
Tomas P
2025-11-07 09:48:57 +01:00
committed by GitHub
parent c0a51aff66
commit 429f82106b

View File

@@ -19,14 +19,21 @@ void ThinknodeM2Board::begin() {
enterDeepSleep(0);
}
uint16_t ThinknodeM2Board::getBattMilliVolts() {
uint16_t ThinknodeM2Board::getBattMilliVolts() {
analogReadResolution(12);
delay(10);
float volts = (analogRead(PIN_VBAT_READ) * ADC_MULTIPLIER * AREF_VOLTAGE) / 4096;
analogReadResolution(10);
return volts * 1000;
}
analogSetPinAttenuation(PIN_VBAT_READ, ADC_11db);
uint32_t mv = 0;
for (int i = 0; i < 8; ++i) {
mv += analogReadMilliVolts(PIN_VBAT_READ);
delayMicroseconds(200);
}
mv /= 8;
analogReadResolution(10);
return static_cast<uint16_t>(mv * ADC_MULTIPLIER );
}
const char* ThinknodeM2Board::getManufacturerName() const {
return "Elecrow ThinkNode M2";
}
}