Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import serial
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- interrupted = False
- def on_key_press(event):
- global interrupted
- if event.key == 'i':
- interrupted = True
- def animate(i, dataList, ser, frequencia):
- ser.write(frequencia)
- arduinoData_string = ser.readline().decode('ascii')
- try:
- arduinoData_float = float(arduinoData_string)
- dataList.append(arduinoData_float)
- except:
- pass
- dataList = dataList[-50:]
- ax.clear()
- ax.plot(dataList)
- ax.set_ylim([0, 1200])
- ax.set_title("Leitura do sensor")
- ax.set_ylabel("ValorLido")
- dataList = []
- fig = plt.figure()
- ax = fig.add_subplot(111)
- ser = serial.Serial("COM6", 9600)
- time.sleep(2)
- freq=input("digite a frequencia(1, 2, 3, 4, 5): ")
- if freq == 1:
- intervalo=200
- elif valor == 2:
- intervalo=400
- elif valor == 3:
- intervalo = 600
- elif valor == 4:
- intervalo = 800
- else:
- intervalo=1000
- while
- ani = animation.FuncAnimation(fig, animate(frequencia=freq), frames=100, fargs=(dataList, ser), interval=intervalo)
- fig.canvas.mpl_connect('key_press_event', on_key_press)
- plt.show()
- ser.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement