/ examples / as726x_simpletest.py
as726x_simpletest.py
 1  import time
 2  
 3  import board
 4  import busio
 5  
 6  # for I2C use:
 7  from adafruit_as726x import AS726x_I2C
 8  
 9  # for UART use:
10  # from adafruit_as726x import AS726x_UART
11  
12  # maximum value for sensor reading
13  max_val = 16000
14  
15  # max number of characters in each graph
16  max_graph = 80
17  
18  
19  def graph_map(x):
20      return min(int(x * max_graph / max_val), max_graph)
21  
22  
23  # for I2C use:
24  i2c = busio.I2C(board.SCL, board.SDA)
25  sensor = AS726x_I2C(i2c)
26  
27  # for UART use:
28  # uart = busio.UART(board.TX, board.RX)
29  # sensor = AS726x_UART(uart)
30  
31  sensor.conversion_mode = sensor.MODE_2
32  
33  while True:
34      # Wait for data to be ready
35      while not sensor.data_ready:
36          time.sleep(0.1)
37  
38      # plot plot the data
39      print("\n")
40      print("V: " + graph_map(sensor.violet) * "=")
41      print("B: " + graph_map(sensor.blue) * "=")
42      print("G: " + graph_map(sensor.green) * "=")
43      print("Y: " + graph_map(sensor.yellow) * "=")
44      print("O: " + graph_map(sensor.orange) * "=")
45      print("R: " + graph_map(sensor.red) * "=")
46  
47      time.sleep(1)