-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectrum.py
44 lines (34 loc) · 848 Bytes
/
spectrum.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
import serial
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from drawnow import *
ser = serial.Serial('COM3', 11200)
plt.ion()
fig = plt.figure()
rects = None
def get_data():
while(ser.inWaiting()==0):
pass
data = ser.readline()
print data
amps = data.split("\t")
amps = amps[:-1]
print amps
amps = [float(amp) for amp in amps]
return len(amps) == 7, amps
def make_graph(data):
rects = plt.bar(range(len(data)), data, align = 'center', color='r')
for rect, h in zip(rects, data):
rect.set_height(h)
fig.canvas.draw()
def main():
while(1):
status, data = get_data()
if not status:
continue
make_graph(data)
plt.pause(.0001)
if __name__ == '__main__':
main()