This repository has been archived on 2025-06-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
compLIB/compLib/Battery.py
Konstantin Lampalzer daef7c97e4
Rename folder
2021-01-16 02:10:40 +01:00

24 lines
532 B
Python

from compLib.ADC import ADC
BATTERY_CHANNEL = 2
BATTERY_COUNT = 2
BATTERY_MULTIPLIER = 3
BATTERY_MIN_VOLTAGE = 3.6
BATTERY_MAX_VOLTAGE = 4.1
adc = ADC()
class Battery(object):
"""Used to interact with the battery
"""
@staticmethod
def percent() -> int:
"""Get battery percentage
:return: Percentage between 0 and 100
:rtype: int
"""
voltage = adc.read(BATTERY_CHANNEL) * BATTERY_MULTIPLIER
return int((voltage - BATTERY_MIN_VOLTAGE) / BATTERY_MAX_VOLTAGE * 100)