-
Notifications
You must be signed in to change notification settings - Fork 0
/
grafmarlegacy.py
58 lines (56 loc) · 1.28 KB
/
grafmarlegacy.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
import matplotlib
try :
matplotlib.use('TkAgg')
except :
matplotlib.use('Qt5Agg')
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from time import sleep
import serial
import time
fine="c"
pre="ciao"
while (fine != "f"):
rawinput("\n\n\n Premi Enter per far partire la registrazione dei dati")
xdata, ydata = [], []
ser = serial.Serial('/dev/ttyACM0', 9600)
while (False):
pre=ser.readline()
pre=ser.readline()
prec = float(pre)
y=prec
fig, ax = plt.subplots()
line, = ax.plot([], [], lw=2)
ax.set_ylim(0, 90)
ax.set_xlim(0, 10)
ax.grid()
def data_gen():
t=0
y=0
cnt=0
p=0
a = ser.readline()
while (True)&(t < 10):
a = ser.readline()
y = float(a)
if (y != 0) :
t = (time.time() - start)
t = float(t)
yield t, y
def run(data):
t,y = data
xdata.append(t)
ydata.append(y)
ax.figure.canvas.draw()
line.set_data(xdata, ydata)
return line,
data_gen.t = 0
while (abs(y-prec) < 2):
if True:
a = ser.readline()
y = float(a)
start = time.time()
ani = animation.FuncAnimation(fig, run, data_gen, blit=True,interval=1,repeat=False)
plt.show()
fine=rawinput("Premi f per finire :")