Skip to content

Instantly share code, notes, and snippets.

@TheRealEdDawson
Created April 10, 2013 03:59
Show Gist options
  • Save TheRealEdDawson/5351692 to your computer and use it in GitHub Desktop.
Save TheRealEdDawson/5351692 to your computer and use it in GitHub Desktop.
A program to measure the output from a photocell sensor.
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