From 2123490280a4fef5d096254d1998a68cf65ed939 Mon Sep 17 00:00:00 2001 From: Dylan Herrada Date: Mon, 14 May 2018 14:45:45 -0400 Subject: [PATCH 1/3] Removed divide-by-zero error when no light is present from example --- examples/tcs34725_simpletest.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/tcs34725_simpletest.py b/examples/tcs34725_simpletest.py index 96cbef7..20e0c78 100644 --- a/examples/tcs34725_simpletest.py +++ b/examples/tcs34725_simpletest.py @@ -18,8 +18,11 @@ r, g, b = sensor.color_rgb_bytes print('Detected color: #{0:02X}{1:02X}{2:02X}'.format(r, g, b)) # Read the color temperature and lux of the sensor too. - temp = sensor.temperature - lux = sensor.lux + try: + temp = sensor.temperature + lux = sensor.lux + except ZeroDivisionError: + print("No light to measure") print('Temperature: {0}K Lux: {1}'.format(temp, lux)) # Delay for a second and repeat. time.sleep(1.0) From 7a847964eda5bfba6e56fda5340fd21d0b7838ab Mon Sep 17 00:00:00 2001 From: Dylan Herrada Date: Mon, 14 May 2018 14:49:48 -0400 Subject: [PATCH 2/3] Moved one more line into try statement --- examples/tcs34725_simpletest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/tcs34725_simpletest.py b/examples/tcs34725_simpletest.py index 20e0c78..c4bb017 100644 --- a/examples/tcs34725_simpletest.py +++ b/examples/tcs34725_simpletest.py @@ -21,8 +21,9 @@ try: temp = sensor.temperature lux = sensor.lux + print('Temperature: {0}K Lux: {1}'.format(temp, lux)) except ZeroDivisionError: print("No light to measure") - print('Temperature: {0}K Lux: {1}'.format(temp, lux)) + # Delay for a second and repeat. time.sleep(1.0) From 3b1324c95af090d82fe256954933d47f405f784d Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Mon, 14 May 2018 16:56:45 -0400 Subject: [PATCH 3/3] Update tcs34725_simpletest.py --- examples/tcs34725_simpletest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/tcs34725_simpletest.py b/examples/tcs34725_simpletest.py index c4bb017..fb20055 100644 --- a/examples/tcs34725_simpletest.py +++ b/examples/tcs34725_simpletest.py @@ -24,6 +24,5 @@ print('Temperature: {0}K Lux: {1}'.format(temp, lux)) except ZeroDivisionError: print("No light to measure") - # Delay for a second and repeat. time.sleep(1.0)