This repository was archived by the owner on Jun 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathread.py
More file actions
40 lines (36 loc) · 1.38 KB
/
Copy pathread.py
File metadata and controls
40 lines (36 loc) · 1.38 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
from datetime import datetime
import RPi.GPIO as GPIO
import csv
RECEIVED_SIGNAL = [[], []] #[[time of reading], [signal reading]]
PIN = int(sys.argv[1])
MAX_DURATION = int(sys.argv[2])
FILE = sys.argv[3]
LAST = 0
if __name__ == '__main__':
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIN, GPIO.IN)
cumulative_time = 0
beginning_time = datetime.now()
print '**Started recording**'
while cumulative_time < MAX_DURATION:
NOW = GPIO.input(PIN)
time_delta = datetime.now() - beginning_time
if NOW != LAST:
RECEIVED_SIGNAL[0].append(time_delta)
RECEIVED_SIGNAL[1].append(LAST)
time_delta = datetime.now() - beginning_time
RECEIVED_SIGNAL[0].append(time_delta)
RECEIVED_SIGNAL[1].append(NOW)
LAST = NOW
cumulative_time = time_delta.seconds
print '**Ended recording**'
print len(RECEIVED_SIGNAL[0]), 'samples recorded'
GPIO.cleanup()
print '**Processing results**'
for i in range(len(RECEIVED_SIGNAL[0])):
RECEIVED_SIGNAL[0][i] = RECEIVED_SIGNAL[0][i].seconds + RECEIVED_SIGNAL[0][i].microseconds/1000000.0
print '**Plotting results**'
with open(FILE, 'wb') as csvfile:
rage = csv.writer(csvfile)
for i in range(len(RECEIVED_SIGNAL[0])):
rage.writerow([RECEIVED_SIGNAL[0][i], RECEIVED_SIGNAL[1][i]])