Simple test

Ensure your device works with this simple test.

examples/tcs34725_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# Simple demo of the TCS34725 color sensor.
 5# Will detect the color from the sensor and print it out every second.
 6import time
 7import board
 8import adafruit_tcs34725
 9
10
11# Create sensor object, communicating over the board's default I2C bus
12i2c = board.I2C()  # uses board.SCL and board.SDA
13# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
14sensor = adafruit_tcs34725.TCS34725(i2c)
15
16# Change sensor integration time to values between 2.4 and 614.4 milliseconds
17# sensor.integration_time = 150
18
19# Change sensor gain to 1, 4, 16, or 60
20# sensor.gain = 4
21
22# Main loop reading color and printing it every second.
23while True:
24    # Raw data from the sensor in a 4-tuple of red, green, blue, clear light component values
25    # print(sensor.color_raw)
26
27    color = sensor.color
28    color_rgb = sensor.color_rgb_bytes
29    print(
30        "RGB color as 8 bits per channel int: #{0:02X} or as 3-tuple: {1}".format(
31            color, color_rgb
32        )
33    )
34
35    # Read the color temperature and lux of the sensor too.
36    temp = sensor.color_temperature
37    lux = sensor.lux
38    print("Temperature: {0}K Lux: {1}\n".format(temp, lux))
39    # Delay for a second and repeat.
40    time.sleep(1.0)