limited battery voltage to two decimal points

This commit is contained in:
2022-12-28 14:58:47 +01:00
parent 35f1059562
commit 290fa03955
2 changed files with 6 additions and 1 deletions
+5
View File
@@ -28,6 +28,11 @@ void Battery::loop() {
this->lastMillis = millis();
}
double Battery::getBatteryVoltage() {
double res = this->batteryVoltage;
return (int)(res*100+0.5)/100.0;
}
double Battery::readInputVoltage() {
// Reference voltage is 3v3 so maximum reading is 3v3 = 4095 in range 0 to 4095
double reading = analogRead(this->pin);
+1 -1
View File
@@ -64,7 +64,7 @@ class Battery {
*
* @return double in Volt
*/
double getBatteryVoltage() {return this->batteryVoltage;}
double getBatteryVoltage();
/**
* @brief Get the charge level of the battery