Created
April 10, 2013 03:59
-
-
Save TheRealEdDawson/5351692 to your computer and use it in GitHub Desktop.
A program to measure the output from a photocell sensor.
This file contains 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
import RPi.GPIO as GPIO, time, os | |
DEBUG = 1 | |
GPIO.setmode(GPIO.BCM) | |
BLUE_LED = 23 | |
GPIO.setup(BLUE_LED, GPIO.OUT) | |
def RCtime (RCpin): | |
reading = 0 | |
GPIO.setup(RCpin, GPIO.OUT) | |
GPIO.output(RCpin, GPIO.LOW) | |
time.sleep(0.1) | |
GPIO.setup(RCpin, GPIO.IN) | |
#This takes about 1 millisecond per loop cycle | |
while (GPIO.input(RCpin) == GPIO.LOW): | |
reading += 1 | |
return reading | |
try: | |
while True: | |
lightlevel = RCtime(18) | |
print lightlevel | |
if lightlevel > 1000: | |
GPIO.output(BLUE_LED, True) | |
else: | |
GPIO.output(BLUE_LED, False) | |
except KeyboardInterrupt: | |
GPIO.cleanup() | |
print "Clean program exit." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment