From 685cf7e2295df7f82de8309611548ac4d245ac4f Mon Sep 17 00:00:00 2001 From: Bojan Korenini Date: Mon, 4 May 2020 22:29:45 +0200 Subject: [PATCH] Update light_sensor.py Sets limit to counts to avoid long delays in sensor readings in the dark. --- light_sensor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/light_sensor.py b/light_sensor.py index 8c28a41..b42dd45 100644 --- a/light_sensor.py +++ b/light_sensor.py @@ -11,6 +11,7 @@ #define the pin that goes to the circuit pin_to_circuit = 7 +max_count = 100000 def rc_time (pin_to_circuit): count = 0 @@ -26,6 +27,8 @@ def rc_time (pin_to_circuit): #Count until the pin goes high while (GPIO.input(pin_to_circuit) == GPIO.LOW): count += 1 + if count == max_count: + break return count