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()
26sensor = AS726x_I2C(i2c)
27
28# for UART use:
29# uart = board.UART()
30# sensor = AS726x_UART(uart)
31
32sensor.conversion_mode = sensor.MODE_2
33
34while True:
35 # Wait for data to be ready
36 while not sensor.data_ready:
37 time.sleep(0.1)
38
39 # plot plot the data
40 print("\n")
41 print("V: " + graph_map(sensor.violet) * "=")
42 print("B: " + graph_map(sensor.blue) * "=")
43 print("G: " + graph_map(sensor.green) * "=")
44 print("Y: " + graph_map(sensor.yellow) * "=")
45 print("O: " + graph_map(sensor.orange) * "=")
46 print("R: " + graph_map(sensor.red) * "=")
47
48 time.sleep(1)