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"""
 9
10import time
11
12import board
13
14import adafruit_husb238
15
16i2c = board.I2C()
17
18# Initialize HUSB238
19pd = adafruit_husb238.Adafruit_HUSB238(i2c)
20voltages = pd.available_voltages
21print("The following voltages are available:")
22for i, volts in enumerate(voltages):
23    print(f"{volts}V")
24
25v = 0
26
27while True:
28    while pd.attached:
29        print(f"Setting to {voltages[v]}V!")
30        pd.voltage = voltages[v]
31        print(f"It is set to {pd.voltage}V/{pd.current}A")
32        print()
33        v = (v + 1) % len(voltages)
34        time.sleep(2)