-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/local/bin/python | ||
|
||
import RPi.GPIO as GPIO | ||
import time | ||
|
||
GPIO.setmode(GPIO.BCM) | ||
|
||
# define the pin that goes to the circuit | ||
pin_to_circuit = 4 | ||
|
||
|
||
def rc_time(pin_to_circuit): | ||
count = 0 | ||
|
||
# Output on the pin for | ||
GPIO.setup(pin_to_circuit, GPIO.OUT) | ||
GPIO.output(pin_to_circuit, GPIO.LOW) | ||
time.sleep(0.1) | ||
|
||
# Change the pin back to input | ||
GPIO.setup(pin_to_circuit, GPIO.IN) | ||
|
||
# Count until the pin goes high | ||
while (GPIO.input(pin_to_circuit) == GPIO.LOW): | ||
count += 1 | ||
|
||
return count | ||
|
||
|
||
# Catch when script is interrupted, cleanup correctly | ||
try: | ||
# Main loop | ||
while True: | ||
print(rc_time(pin_to_circuit)) | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
GPIO.cleanup() |