From 17e411a5f3a6a7b5749dd400fbd4164366841519 Mon Sep 17 00:00:00 2001 From: Josh Gadeken Date: Wed, 3 Oct 2018 20:34:22 -0600 Subject: [PATCH 1/2] Add color property to the TCS34725 class (closes #8). --- adafruit_tcs34725.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/adafruit_tcs34725.py b/adafruit_tcs34725.py index 893ae91..cd0561b 100644 --- a/adafruit_tcs34725.py +++ b/adafruit_tcs34725.py @@ -242,6 +242,16 @@ def color_rgb_bytes(self): blue = int(pow((int((b/clear) * 256) / 255), 2.5) * 255) return (red, green, blue) + @property + def color(self): + """Read the RGB color detected by the sensor. Returns an int with 8 bits per channel. + + Examples: Red = 16711680 (0xff0000), Green = 65280 (0x00ff00), + Blue = 255 (0x0000ff), SlateGray = 7372944 (0x708090) + """ + r, g, b = self.color_rgb_bytes + return (r << 16) + (g << 8) + b + @property def temperature(self): From a6f093009e44491c8b3eeeadd3ba3108260c38e4 Mon Sep 17 00:00:00 2001 From: Josh Gadeken Date: Thu, 4 Oct 2018 16:46:20 -0600 Subject: [PATCH 2/2] Use bitwise 'or' to combine r, g, and b. For consistency, switch from '+' to '|' since bitwise operations are already being used. https://github.com/adafruit/Adafruit_CircuitPython_TCS34725/pull/13#discussion_r222834261 --- adafruit_tcs34725.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_tcs34725.py b/adafruit_tcs34725.py index cd0561b..a5951de 100644 --- a/adafruit_tcs34725.py +++ b/adafruit_tcs34725.py @@ -250,7 +250,7 @@ def color(self): Blue = 255 (0x0000ff), SlateGray = 7372944 (0x708090) """ r, g, b = self.color_rgb_bytes - return (r << 16) + (g << 8) + b + return (r << 16) | (g << 8) | b @property