-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestRadWatch.py
More file actions
86 lines (62 loc) · 1.61 KB
/
testRadWatch.py
File metadata and controls
86 lines (62 loc) · 1.61 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#Measures Temperature, Humidity, Pressure, Air Quality, and Radiation
#region imports
import serial
import time
import board
import csv
import numpy as np
import sys
import datetime as dt
import RPi.GPIO as GPIO
#endregion
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)
times = []
counts = 0
def callBack(channel):
global counts
if GPIO.input(17):
counts += 1
run_time = int(sys.argv[1])
sleep_time = float(sys.argv[2])
ready_time = int(sys.argv[3])
ready_time = 60*ready_time
time.sleep(ready_time)
GPIO.add_event_detect(17, GPIO.BOTH, callback=callBack)
averageCPM = 0
averageCPS = 0
listaverageCPS = []
listaverageCPM = []
n = 0
current_time = time.time()
stop_time = time.time()+(run_time*60)
while current_time < stop_time:
time.sleep(sleep_time)
times.append(time.time())
averageCPM = counts
averageCPS = counts/60
listaverageCPS.append(averageCPS)
listaverageCPM.append(averageCPM)
counts = 0
current_time = time.time()
GPIO.cleanup()
print("Done!")
times_int = []
times_int = np.array(times, dtype='int')
dateCreation = dt.datetime.now()
dateCreation = str(dateCreation.replace(microsecond = 0))
def remove(string):
return string.replace(" ", "--")
date = remove(dateCreation)
filename = 'RadiationData--' + date + '.csv'
print("File Name:",filename)
file = open(filename, 'w')
length = len(times)
i = 0
with file:
header = ['Time (Unix)','CPS','CPM']
writer = csv.DictWriter(file, fieldnames = header)
writer.writeheader()
while i < length:
writer.writerow({'Time (Unix)':times_int[i],'CPS':listaverageCPS[i],'CPM':listaverageCPM[i]})
i+=1