Simple test

Ensure your device works with this simple test.

examples/husb238_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2023 Liz Clark for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4"""
 5Simple test for the HUSB238.
 6Reads available voltages and then sets each available voltage.
 7Reads the set voltage and current from the attached PD power supply.
 8"""
 9import time
10import board
11import adafruit_husb238
12
13i2c = board.I2C()
14
15# Initialize HUSB238
16pd = adafruit_husb238.Adafruit_HUSB238(i2c)
17voltages = pd.available_voltages
18print("The following voltages are available:")
19for i, volts in enumerate(voltages):
20    print(f"{volts}V")
21
22v = 0
23
24while True:
25    while pd.attached:
26        print(f"Setting to {voltages[v]}V!")
27        pd.voltage = voltages[v]
28        print(f"It is set to {pd.voltage}V/{pd.current}A")
29        print()
30        v = (v + 1) % len(voltages)
31        time.sleep(2)