Skip to content

Commit

Permalink
πŸ› fix: ESP32 can get electricity value correctly
Browse files Browse the repository at this point in the history
Closes #4 -Battery Test
  • Loading branch information
Hsun1031 committed Mar 20, 2023
1 parent 898735d commit 6e9d02a
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/components/module/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ void setup_battery(Battery_conf *conf) {
*/
uint8_t get_electricity() {
uint16_t electricity = analogRead(_battery_conf->pin);
uint32_t batter_value = (_battery_conf->max - _battery_conf->min) * 100;

if(electricity < _battery_conf->min) {
return 0;
Expand All @@ -31,7 +30,7 @@ uint8_t get_electricity() {
}

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

uint16_t get_electricity_value() {
Expand Down

0 comments on commit 6e9d02a

Please sign in to comment.