Advertisement
damesova

1

Mar 28th, 2023
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | Source Code | 0 0
  1.  
  2. #imports for matplotlib
  3. import matplotlib.pyplot as plt
  4. from matplotlib.animation import FuncAnimation
  5.  
  6. #Add Phidgets Library
  7. from Phidget22.Phidget import *
  8. from Phidget22.Devices.TemperatureSensor import *
  9.  
  10. fig, ax = plt.subplots()
  11. size = 100 #modify this for more or less points on graph
  12. xdata = range(0, size) #x-axis values
  13. ydata = [0] * size #y-axis values
  14. ln, = plt.plot(xdata, ydata, 'ro-')
  15.  
  16. #Create, open, set data interval
  17. temperature = TemperatureSensor()
  18. temperature.setChannel(0)
  19. temperature.openWaitForAttachment(1000)
  20. temperature.setDataInterval(temperature.getMinDataInterval())
  21.    
  22. def init():
  23.     ax.set(xlabel='samples', ylabel='temperature (°C)',
  24.        title='Getting Started Kit')
  25.     ax.set_xlim(0, size)
  26.     ax.set_ylim(10, 30) #expected range of temperature
  27.     return ln,
  28.  
  29. def update(i, ydata):
  30.     ydata.append(temperature.getTemperature())
  31.     ydata = ydata[-size:]
  32.     ln.set_ydata(ydata)    
  33.     return ln,
  34.  
  35. ani = FuncAnimation(fig,
  36.                     update,
  37.                     fargs=(ydata,),
  38.                     init_func=init,
  39.                     interval=temperature.getDataInterval(),
  40.                     blit=True)
  41. plt.show()
  42.  
Tags: mom
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement