Skip to content

Commit 6e9d02a

Browse files
committed
šŸ› fix: ESP32 can get electricity value correctly
Closes #4 -Battery Test
1 parent 898735d commit 6e9d02a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

ā€Žsrc/components/module/battery.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ void setup_battery(Battery_conf *conf) {
2020
*/
2121
uint8_t get_electricity() {
2222
uint16_t electricity = analogRead(_battery_conf->pin);
23-
uint32_t batter_value = (_battery_conf->max - _battery_conf->min) * 100;
2423

2524
if(electricity < _battery_conf->min) {
2625
return 0;
@@ -31,7 +30,7 @@ uint8_t get_electricity() {
3130
}
3231

3332
// Scale the analog input value to a percentage between 0 and 100
34-
return ( (electricity - _battery_conf->min) / batter_value );
33+
return ( ( (electricity - _battery_conf->min) * 100 ) / (_battery_conf->max - _battery_conf->min) );
3534
}
3635

3736
uint16_t get_electricity_value() {

0 commit comments

Comments
Ā (0)