Simple test

Ensure your device works with this simple test.

examples/ds3502_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4from time import sleep
 5import board
 6from analogio import AnalogIn
 7import adafruit_ds3502
 8
 9####### NOTE ################
10# this example will not work with Blinka/rasberry Pi due to the lack of analog pins.
11# Blinka and Raspberry Pi users should run the "ds3502_blinka_simpletest.py" example
12
13i2c = board.I2C()  # uses board.SCL and board.SDA
14# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
15ds3502 = adafruit_ds3502.DS3502(i2c)
16wiper_output = AnalogIn(board.A0)
17
18while True:
19    ds3502.wiper = 127
20    print("Wiper set to %d" % ds3502.wiper)
21    voltage = wiper_output.value
22    voltage *= 3.3
23    voltage /= 65535
24    print("Wiper voltage: %.2f V" % voltage)
25    print("")
26    sleep(1.0)
27
28    ds3502.wiper = 0
29    print("Wiper set to %d" % ds3502.wiper)
30    voltage = wiper_output.value
31    voltage *= 3.3
32    voltage /= 65535
33    print("Wiper voltage: %.2f V" % voltage)
34    print("")
35    sleep(1.0)
36
37    ds3502.wiper = 63
38    print("Wiper set to %d" % ds3502.wiper)
39    voltage = wiper_output.value
40    voltage *= 3.3
41    voltage /= 65535
42    print("Wiper voltage: %.2f V" % voltage)
43    print("")
44    sleep(1.0)