-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay.py
81 lines (61 loc) · 1.55 KB
/
display.py
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
import serial
import time
import numpy as np
import matplotlib.pyplot as plt
# import plotly.plotly as py
import RPi.GPIO as GPIO
# Change string to integer
def parseInt(x):
try:
return int(x);
except ValueError:
return None;
# Write data to txt file
def write2file(string):
file = open("data.txt", "a");
file.write(string+'\n');
print string;
file.close();
# Reset trigger
GPIO.setmode(GPIO.BOARD);
GPIO.setup(16, GPIO.IN);
start_time = round(time.time(), 5);
input_data = serial.Serial('/dev/ttyUSB0',115200);
bins = [1,2,3,4,5,6,7,8,9]
counter = [0]*9;
muon = [];
write2file('===Start counting from '+str(start_time)+'===');
plt.ion();
while True:
if not GPIO.input(16):
counter = [0]*9;
else:
event = parseInt(input_data.read());
print(event);
if event!=None and event>=1 and event<=9:
# Write into file.
counter[event-1] += 1;
muon += [event];
# print muon;
current_time = round(time.time(),5);
write2file(str(current_time)+','+str(counter));
# Plot histogram.
fig_name = "./bar/fig_" + str(len(muon));
plt.cla();
# plt.hist(muon,bins);
plt.title("Histogram");
plt.xlabel("No.");
plt.ylabel("Count");
objects = ('1','2','3','4','5','6','7','8','9');
y_pos = np.arange(len(objects));
# performance = [10,8,6,4,2,1];
plt.bar(y_pos, counter, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
# plt.ylabel('Usage')
# plt.title('Programming language usage')
plt.draw();
plt.show();
# plt.savefig(fig_name);
plt.pause(0.01);
# file.close();
s.close()