Created
July 11, 2016 15:18
-
-
Save Sciss/ff9d443546607f72d0b10784abf9e476 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
| #!/usr/bin/env python | |
| # https://learn.adafruit.com/basic-resistor-sensor-reading-on-raspberry-pi/basic-photocell-reading | |
| # Example for RC timing reading for Raspberry Pi | |
| # Must be used with GPIO 0.3.1a or later - earlier verions | |
| # are not fast enough! | |
| import RPi.GPIO as GPIO, time, os | |
| DEBUG = 1 | |
| GPIO.setmode(GPIO.BCM) | |
| 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 | |
| while True: | |
| print RCtime(18) # Read RC timing using pin #18 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment