Created
October 4, 2018 02:52
-
-
Save process1183/39c2d4a551ac8ccfa03ed33fc3172f2b to your computer and use it in GitHub Desktop.
Modified copy of Adafruit_CircuitPython_TCS34725/examples/tcs34725_simpletest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Modified copy of https://github.com/adafruit/Adafruit_CircuitPython_TCS34725/blob/master/examples/tcs34725_simpletest.py | |
# Simple demo of the TCS34725 color sensor. | |
# Will detect the color from the sensor and print it out every second. | |
import time | |
import board | |
import busio | |
import adafruit_tcs34725 | |
# Initialize I2C bus and sensor. | |
i2c = busio.I2C(board.SCL, board.SDA) | |
sensor = adafruit_tcs34725.TCS34725(i2c) | |
# Main loop reading color and printing it every second. | |
while True: | |
# Read the color as RGB bytes (0-255 values). | |
r, g, b = sensor.color_rgb_bytes | |
color = sensor.color | |
print('Detected color: #{0:02X}{1:02X}{2:02X}'.format(r, g, b)) | |
print("sensor.color = {} #{:06X}".format(color, color)) | |
# Read the color temperature and lux of the sensor too. | |
try: | |
temp = sensor.temperature | |
lux = sensor.lux | |
print('Temperature: {0}K Lux: {1}'.format(temp, lux)) | |
except ZeroDivisionError: | |
print("No light to measure") | |
print() | |
# Delay for a second and repeat. | |
time.sleep(1.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment