Simple test

Ensure your device works with this simple test.

examples/as726x_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board

# for I2C use:
from adafruit_as726x import AS726x_I2C

# for UART use:
# from adafruit_as726x import AS726x_UART

# maximum value for sensor reading
max_val = 16000

# max number of characters in each graph
max_graph = 80


def graph_map(x):
    return min(int(x * max_graph / max_val), max_graph)


# for I2C use:
i2c = board.I2C()
sensor = AS726x_I2C(i2c)

# for UART use:
# uart = board.UART()
# sensor = AS726x_UART(uart)

sensor.conversion_mode = sensor.MODE_2

while True:
    # Wait for data to be ready
    while not sensor.data_ready:
        time.sleep(0.1)

    # plot plot the data
    print("\n")
    print("V: " + graph_map(sensor.violet) * "=")
    print("B: " + graph_map(sensor.blue) * "=")
    print("G: " + graph_map(sensor.green) * "=")
    print("Y: " + graph_map(sensor.yellow) * "=")
    print("O: " + graph_map(sensor.orange) * "=")
    print("R: " + graph_map(sensor.red) * "=")

    time.sleep(1)