-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphotoresistor.py
More file actions
44 lines (32 loc) · 874 Bytes
/
Copy pathphotoresistor.py
File metadata and controls
44 lines (32 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/local/bin/python
import time
import RPi.GPIO as GPIO
def rc_time(input_pin):
count = 0
# Output on the pin for
GPIO.setup(input_pin, GPIO.OUT)
GPIO.output(input_pin, GPIO.LOW)
time.sleep(0.1)
# Change the pin back to input
GPIO.setup(input_pin, GPIO.IN)
# Count until the pin goes high
while (GPIO.input(input_pin) == GPIO.LOW):
count += 1
return count
def main():
GPIO.setmode(GPIO.BOARD)
input_pin = 18
# Catch when script is interrupted, cleanup correct
try:
# Main loop
while True:
if (rc_time(input_pin) < 1000):
# print "Someone has entered the room!"
print rc_time(input_pin)
time.sleep(.1)
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
if __name__ == '__main__':
main()