Added battery status by hub LED color
This commit is contained in:
1 parent
25121005bd
commit
7c3c639800
1 file changed
+22
-1
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
from pybricks.hubs import TechnicHub
|
from pybricks.hubs import TechnicHub
|
||||||
from pybricks.pupdevices import Motor, Remote
|
from pybricks.pupdevices import Motor, Remote
|
||||||
from pybricks.parameters import Port, Direction, Stop, Button
|
from pybricks.parameters import Port, Direction, Stop, Button, Color
|
||||||
from pybricks.tools import wait
|
from pybricks.tools import wait
|
||||||
from uerrno import ENODEV
|
from uerrno import ENODEV
|
||||||
|
|
||||||
@@ -84,6 +84,10 @@ while x < 4:
|
|||||||
track_switch[x].run_target(200, -track_switch_angle[x], Stop.COAST, False)
|
track_switch[x].run_target(200, -track_switch_angle[x], Stop.COAST, False)
|
||||||
x = x + 1
|
x = x + 1
|
||||||
|
|
||||||
|
# Battery variables
|
||||||
|
voltage_current = hub.battery.voltage()
|
||||||
|
voltage = voltage_current
|
||||||
|
|
||||||
# Main program.
|
# Main program.
|
||||||
while True:
|
while True:
|
||||||
# Check which buttons are pressed.
|
# Check which buttons are pressed.
|
||||||
@@ -166,5 +170,22 @@ while True:
|
|||||||
switch_track_switch[x] = 0
|
switch_track_switch[x] = 0
|
||||||
x = x + 1
|
x = x + 1
|
||||||
|
|
||||||
|
# Show battery status by hub LED.
|
||||||
|
# Get current voltage and gradually up or down the value.
|
||||||
|
voltage_current = hub.battery.voltage()
|
||||||
|
if voltage_current < voltage:
|
||||||
|
voltage -= 1
|
||||||
|
elif voltage_current > voltage:
|
||||||
|
voltage += 1
|
||||||
|
# Show the correct color.
|
||||||
|
if voltage > 9000:
|
||||||
|
hub.light.on(Color.GREEN)
|
||||||
|
elif voltage > 8100:
|
||||||
|
hub.light.on(Color.YELLOW)
|
||||||
|
elif voltage > 7200:
|
||||||
|
hub.light.on(Color.ORANGE)
|
||||||
|
else:
|
||||||
|
hub.light.on(Color.RED)
|
||||||
|
|
||||||
# Wait.
|
# Wait.
|
||||||
wait(10)
|
wait(10)
|
||||||
Reference in new issue
Block a user