From a3e1a48a88ce61b0267de4165b338958dda77aac Mon Sep 17 00:00:00 2001 From: Vi Date: Wed, 30 Jun 2021 14:45:28 +0200 Subject: [PATCH 1/4] Initial commit. --- adafruit_tcs34725.py | 7 +++++++ examples/tcs34725_simpletest.py | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/adafruit_tcs34725.py b/adafruit_tcs34725.py index e4e379f..98658a8 100644 --- a/adafruit_tcs34725.py +++ b/adafruit_tcs34725.py @@ -134,12 +134,19 @@ def color_rgb_bytes(self): red, green, blue component values as bytes (0-255). """ r, g, b, clear = self.color_raw + # Avoid divide by zero errors ... if clear = 0 return black if clear == 0: return (0, 0, 0) + + """Each color value is normalized to clear, to obtain int values between 0 and 255. + A gamma correction of 2.5 is applied to each value as well, first dividing by 255, + since gamma is applied to values between 0 and 1 + """ red = int(pow((int((r / clear) * 256) / 255), 2.5) * 255) green = int(pow((int((g / clear) * 256) / 255), 2.5) * 255) blue = int(pow((int((b / clear) * 256) / 255), 2.5) * 255) + # Handle possible 8-bit overflow if red > 255: red = 255 diff --git a/examples/tcs34725_simpletest.py b/examples/tcs34725_simpletest.py index 3823499..292147d 100644 --- a/examples/tcs34725_simpletest.py +++ b/examples/tcs34725_simpletest.py @@ -12,11 +12,24 @@ i2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_tcs34725.TCS34725(i2c) +# Change sensor integration time to values between 2.4 and 614.4 milliseconds +# sensor.integration_time = 150 + +# Change sensor gain to 1, 4, 16, or 60 +# sensor.gain = 4 + # Main loop reading color and printing it every second. while True: + # Raw data from the sensor in a 4-tuple of red, green, blue, clear light component values + # print(sensor.color_raw) + + color = sensor.color + color_rgb = sensor.color_rgb_bytes + print("RGB color as 8 bits per channel int: #{0:02X} or as 3-tuple: {1}".format(color, color_rgb)) + # Read the color temperature and lux of the sensor too. temp = sensor.color_temperature lux = sensor.lux - print("Temperature: {0}K Lux: {1}".format(temp, lux)) + print("Temperature: {0}K Lux: {1}\n".format(temp, lux)) # Delay for a second and repeat. time.sleep(1.0) From 12ef02c10956b95dcbbdeae8dce0ccf14fe3f8c5 Mon Sep 17 00:00:00 2001 From: Vi Date: Wed, 30 Jun 2021 17:09:37 +0200 Subject: [PATCH 2/4] ... --- adafruit_tcs34725.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adafruit_tcs34725.py b/adafruit_tcs34725.py index 98658a8..1e9bba7 100644 --- a/adafruit_tcs34725.py +++ b/adafruit_tcs34725.py @@ -141,8 +141,7 @@ def color_rgb_bytes(self): """Each color value is normalized to clear, to obtain int values between 0 and 255. A gamma correction of 2.5 is applied to each value as well, first dividing by 255, - since gamma is applied to values between 0 and 1 - """ + since gamma is applied to values between 0 and 1 """ red = int(pow((int((r / clear) * 256) / 255), 2.5) * 255) green = int(pow((int((g / clear) * 256) / 255), 2.5) * 255) blue = int(pow((int((b / clear) * 256) / 255), 2.5) * 255) From c36f072bf3c2db4a7a426282292b59b74d1d640d Mon Sep 17 00:00:00 2001 From: Vi Date: Wed, 30 Jun 2021 17:36:14 +0200 Subject: [PATCH 3/4] correct comment this time --- adafruit_tcs34725.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_tcs34725.py b/adafruit_tcs34725.py index 1e9bba7..d0b5f68 100644 --- a/adafruit_tcs34725.py +++ b/adafruit_tcs34725.py @@ -139,9 +139,9 @@ def color_rgb_bytes(self): if clear == 0: return (0, 0, 0) - """Each color value is normalized to clear, to obtain int values between 0 and 255. - A gamma correction of 2.5 is applied to each value as well, first dividing by 255, - since gamma is applied to values between 0 and 1 """ + # Each color value is normalized to clear, to obtain int values between 0 and 255. + # A gamma correction of 2.5 is applied to each value as well, first dividing by 255, + # since gamma is applied to values between 0 and 1 red = int(pow((int((r / clear) * 256) / 255), 2.5) * 255) green = int(pow((int((g / clear) * 256) / 255), 2.5) * 255) blue = int(pow((int((b / clear) * 256) / 255), 2.5) * 255) From 6f4fb3af5ddb39ee4574359fca9fa57a13f060b9 Mon Sep 17 00:00:00 2001 From: Vi Date: Wed, 30 Jun 2021 20:55:03 +0200 Subject: [PATCH 4/4] hoping --- examples/tcs34725_simpletest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/tcs34725_simpletest.py b/examples/tcs34725_simpletest.py index 292147d..7a3059d 100644 --- a/examples/tcs34725_simpletest.py +++ b/examples/tcs34725_simpletest.py @@ -25,7 +25,11 @@ color = sensor.color color_rgb = sensor.color_rgb_bytes - print("RGB color as 8 bits per channel int: #{0:02X} or as 3-tuple: {1}".format(color, color_rgb)) + print( + "RGB color as 8 bits per channel int: #{0:02X} or as 3-tuple: {1}".format( + color, color_rgb + ) + ) # Read the color temperature and lux of the sensor too. temp = sensor.color_temperature