Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5import board
6
7# for I2C use:
8from adafruit_as726x import AS726x_I2C
9
10# for UART use:
11# from adafruit_as726x import AS726x_UART
12
13# maximum value for sensor reading
14max_val = 16000
15
16# max number of characters in each graph
17max_graph = 80
18
19
20def graph_map(x):
21 return min(int(x * max_graph / max_val), max_graph)
22
23
24# for I2C use:
25i2c = board.I2C() # uses board.SCL and board.SDA
26# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
27sensor = AS726x_I2C(i2c)
28
29# for UART use:
30# uart = board.UART()
31# sensor = AS726x_UART(uart)
32
33sensor.conversion_mode = sensor.MODE_2
34
35while True:
36 # Wait for data to be ready
37 while not sensor.data_ready:
38 time.sleep(0.1)
39
40 # plot plot the data
41 print("\n")
42 print("V: " + graph_map(sensor.violet) * "=")
43 print("B: " + graph_map(sensor.blue) * "=")
44 print("G: " + graph_map(sensor.green) * "=")
45 print("Y: " + graph_map(sensor.yellow) * "=")
46 print("O: " + graph_map(sensor.orange) * "=")
47 print("R: " + graph_map(sensor.red) * "=")
48
49 time.sleep(1)