Skip to content

Commit

Permalink
Merge pull request #890 from lurch/patch-1
Browse files Browse the repository at this point in the history
Prevent negative light values
  • Loading branch information
waveform80 committed Mar 1, 2021
2 parents a9850a8 + 54f8a7c commit 7949f49
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gpiozero/input_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,18 +723,18 @@ def _read(self):
self.pin.function = 'output'
self.pin.state = False
sleep(0.1)
# Time the charging of the capacitor
start = self.pin_factory.ticks()
self._charge_time = None
self._charged.clear()
# Time the charging of the capacitor
start = self.pin_factory.ticks()
self.pin.function = 'input'
self._charged.wait(self.charge_time_limit)
if self._charge_time is None:
return 0.0
else:
return 1.0 - (
self.pin_factory.ticks_diff(self._charge_time, start) /
self.charge_time_limit)
return 1.0 - min(1.0,
(self.pin_factory.ticks_diff(self._charge_time, start) /
self.charge_time_limit))

@property
def value(self):
Expand Down

0 comments on commit 7949f49

Please sign in to comment.