31 lines
798 B
Python
31 lines
798 B
Python
import time
|
|
import board
|
|
import busio
|
|
import digitalio
|
|
from adafruit_apds9960.apds9960 import APDS9960
|
|
from adafruit_apds9960 import colorutility
|
|
|
|
i2c = busio.I2C(board.SCL, board.SDA)
|
|
int_pin = digitalio.DigitalInOut(board.A2)
|
|
apds = APDS9960(i2c)
|
|
apds.enable_color = True
|
|
|
|
|
|
while True:
|
|
#create some variables to store the color data in
|
|
|
|
#wait for color data to be ready
|
|
while not apds.color_data_ready:
|
|
time.sleep(0.005)
|
|
|
|
|
|
#get the data and print the different channels
|
|
r, g, b, c = apds.color_data
|
|
print("red: ", r)
|
|
print("green: ", g)
|
|
print("blue: ", b)
|
|
print("clear: ", c)
|
|
|
|
print("color temp {}".format(colorutility.calculate_color_temperature(r, g, b)))
|
|
print("light lux {}".format(colorutility.calculate_lux(r, g, b)))
|
|
time.sleep(0.5)
|