#!/usr/bin/env python3
#
# https://www.dexterindustries.com/BrickPi/
# https://github.com/DexterInd/BrickPi3
#
# Copyright (c) 2026 Modular Robotics Inc
# Released under the MIT license (http://choosealicense.com/licenses/mit/).
# For more information see https://github.com/DexterInd/BrickPi3/blob/master/LICENSE.md
#
# This code is an example for reading BrickPi3 power supply voltage
#
# Results: Print the voltages measured by the BrickPi3 power supply monitor.

import time     # import the time library for the sleep function
import brickpi3 # import the BrickPi3 drivers

BP = brickpi3.BrickPi3() # Create an instance of the BrickPi3 class. BP will be the BrickPi3 object.

try:
    while True:
        print(f"Battery voltage: {BP.get_voltage_battery():6.3f}  9v voltage: {BP.get_voltage_9v():6.3f}  5v voltage: {BP.get_voltage_5v():6.3f}  3.3v voltage: {BP.get_voltage_3v3():6.3f}") # read and display the current voltages

        time.sleep(0.02)  # delay for 0.02 seconds (20ms) to reduce the Raspberry Pi CPU load.

except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard.
    BP.reset_all()        # Unconfigure the sensors, disable the motors, and restore the LED to the control of the BrickPi3 firmware.
