Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb9154be

Browse files
battery_voltage: read ADC 10 times
1 parent51716d3 commitb9154be

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

‎internal_filesystem/lib/mpos/battery_voltage.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ def read_battery_voltage():
2121
importrandom
2222
returnrandom.randint(370,420)/100
2323
# Read raw ADC value
24-
raw_value=adc.read()
24+
total=0
25+
# Read multiple times to try to reduce variability.
26+
# Reading 10 times takes around 3ms so it's fine...
27+
for_inrange(10):
28+
total=total+adc.read()
29+
raw_value=total/10
2530
# Convert to voltage, accounting for divider and reference
2631
voltage= (raw_value/ADC_MAX)*VREF*VOLTAGE_DIVIDER
2732
# Clamp to 0–4.2V range for LiPo battery

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp