We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 51716d3 commit b9154beCopy full SHA for b9154be
internal_filesystem/lib/mpos/battery_voltage.py
@@ -21,7 +21,12 @@ def read_battery_voltage():
21
import random
22
return random.randint(370,420) / 100
23
# Read raw ADC value
24
- raw_value = adc.read()
+ total = 0
25
+ # Read multiple times to try to reduce variability.
26
+ # Reading 10 times takes around 3ms so it's fine...
27
+ for _ in range(10):
28
+ total = total + adc.read()
29
+ raw_value = total / 10
30
# Convert to voltage, accounting for divider and reference
31
voltage = (raw_value / ADC_MAX) * VREF * VOLTAGE_DIVIDER
32
# Clamp to 0–4.2V range for LiPo battery
0 commit comments