Last active
August 26, 2018 18:53
-
-
Save bennuttall/9b4da3270b3e576e26eb9be2460d738d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from gpiozero import LightSensor | |
| from time import time, sleep | |
| class NoisyLightSensor(LightSensor): | |
| def _read(self): | |
| # Drain charge from the capacitor | |
| self.pin.function = 'output' | |
| self.pin.state = False | |
| sleep(0.1) | |
| # Time the charging of the capacitor | |
| start = time() | |
| self._charged.clear() | |
| self.pin.function = 'input' | |
| self._charged.wait(self.charge_time_limit) | |
| value = ( | |
| 1.0 - min(self.charge_time_limit, time() - start) / | |
| self.charge_time_limit | |
| ) | |
| print('Charge time: {}'.format(value)) | |
| return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment