Created
January 2, 2019 15:40
-
-
Save sergiomtzlosa/da86cbd298d91240b382023690ae7e03 to your computer and use it in GitHub Desktop.
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
#!/bin/python | |
import RPi.GPIO as GPIO | |
import time | |
LOG_PERIOD = 20000 | |
MINUTE_PERIOD = 60000 | |
counts = 0 | |
cpm = 0 | |
inputPin = 14 # set input GPIO pin number here | |
global previousMillis | |
previousMillis = 0 | |
GPIO.setwarnings(False) | |
GPIO.setmode(GPIO.BCM) | |
def geiger_click(channel): | |
global counts | |
counts = counts + 1 | |
print "click" | |
GPIO.setup(inputPin, GPIO.IN) | |
GPIO.add_event_detect(inputPin, GPIO.RISING, callback=geiger_click) | |
try: | |
while(True): | |
currentMillis = int(round(time.time() * 1000)) | |
if (currentMillis - previousMillis > LOG_PERIOD): | |
previousMillis = currentMillis | |
cpm = counts * MINUTE_PERIOD / LOG_PERIOD | |
print str(cpm) + " cpm" | |
counts = 0 | |
except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly: | |
pass | |
except: | |
pass | |
finally: | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment