Skip to content

Instantly share code, notes, and snippets.

@bennuttall
Last active November 14, 2018 10:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bennuttall/d0a4b7b4bd5b4b872f67e0696b21911a to your computer and use it in GitHub Desktop.
from gpiozero import InputDevice, OutputDevice
from time import time, sleep
def read_light_sensor(pin):
with OutputDevice(pin) as cap:
cap.value = 0
sleep(0.1)
# Time the charging of the capacitor
start = time()
with InputDevice(pin) as ldr:
charge_time_limit = 0.01
ldr.wait_for_active(timeout=charge_time_limit)
value = (
1.0 - min(charge_time_limit, time() - start) /
charge_time_limit
)
print('Charge time: {}'.format(value))
while True:
read_light_sensor(14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment