-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoodRadWatch.py
More file actions
37 lines (27 loc) · 897 Bytes
/
GoodRadWatch.py
File metadata and controls
37 lines (27 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import RPi.GPIO as GPIO
import time
import sys
import numpy as np
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)
counts = 0
def callBack(channel):
global counts
if GPIO.input(17): # if port 17 == 1
print ("Count Detected!")
counts += 1
GPIO.add_event_detect(17, GPIO.BOTH, callback=callBack)
try:
print ("When pressed, you'll see: Rising Edge detected on 25")
print ("When released, you'll see: Falling Edge detected on 25" )
sleep_time = int(sys.argv[1])
i = 0
averageCPM = []
while i < sleep_time:
time.sleep(60)
i+=1
averageCPM.append(counts/60)
counts = 0
finally: # this block will run no matter how the try block exits
print ("The average counts per second each minute was: ", averageCPM)
GPIO.cleanup()