/ examples / color.py
color.py
 1  import time
 2  import board
 3  import busio
 4  import digitalio
 5  from adafruit_apds9960.apds9960 import APDS9960
 6  from adafruit_apds9960 import colorutility
 7  
 8  i2c = busio.I2C(board.SCL, board.SDA)
 9  int_pin = digitalio.DigitalInOut(board.A2)
10  apds = APDS9960(i2c)
11  apds.enable_color = True
12  
13  
14  while True:
15      #create some variables to store the color data in
16  
17      #wait for color data to be ready
18      while not apds.color_data_ready:
19          time.sleep(0.005)
20  
21  
22      #get the data and print the different channels
23      r, g, b, c = apds.color_data
24      print("red: ", r)
25      print("green: ", g)
26      print("blue: ", b)
27      print("clear: ", c)
28  
29      print("color temp {}".format(colorutility.calculate_color_temperature(r, g, b)))
30      print("light lux {}".format(colorutility.calculate_lux(r, g, b)))
31      time.sleep(0.5)