Skip to content

Commit a3e1a48

Browse files
committed
Initial commit.
1 parent 239f5ba commit a3e1a48

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

adafruit_tcs34725.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,19 @@ def color_rgb_bytes(self):
134134
red, green, blue component values as bytes (0-255).
135135
"""
136136
r, g, b, clear = self.color_raw
137+
137138
# Avoid divide by zero errors ... if clear = 0 return black
138139
if clear == 0:
139140
return (0, 0, 0)
141+
142+
"""Each color value is normalized to clear, to obtain int values between 0 and 255.
143+
A gamma correction of 2.5 is applied to each value as well, first dividing by 255,
144+
since gamma is applied to values between 0 and 1
145+
"""
140146
red = int(pow((int((r / clear) * 256) / 255), 2.5) * 255)
141147
green = int(pow((int((g / clear) * 256) / 255), 2.5) * 255)
142148
blue = int(pow((int((b / clear) * 256) / 255), 2.5) * 255)
149+
143150
# Handle possible 8-bit overflow
144151
if red > 255:
145152
red = 255

examples/tcs34725_simpletest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@
1212
i2c = board.I2C() # uses board.SCL and board.SDA
1313
sensor = adafruit_tcs34725.TCS34725(i2c)
1414

15+
# Change sensor integration time to values between 2.4 and 614.4 milliseconds
16+
# sensor.integration_time = 150
17+
18+
# Change sensor gain to 1, 4, 16, or 60
19+
# sensor.gain = 4
20+
1521
# Main loop reading color and printing it every second.
1622
while True:
23+
# Raw data from the sensor in a 4-tuple of red, green, blue, clear light component values
24+
# print(sensor.color_raw)
25+
26+
color = sensor.color
27+
color_rgb = sensor.color_rgb_bytes
28+
print("RGB color as 8 bits per channel int: #{0:02X} or as 3-tuple: {1}".format(color, color_rgb))
29+
1730
# Read the color temperature and lux of the sensor too.
1831
temp = sensor.color_temperature
1932
lux = sensor.lux
20-
print("Temperature: {0}K Lux: {1}".format(temp, lux))
33+
print("Temperature: {0}K Lux: {1}\n".format(temp, lux))
2134
# Delay for a second and repeat.
2235
time.sleep(1.0)

0 commit comments

Comments
 (0)