Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #imports for matplotlib
- import matplotlib.pyplot as plt
- from matplotlib.animation import FuncAnimation
- #Add Phidgets Library
- from Phidget22.Phidget import *
- from Phidget22.Devices.TemperatureSensor import *
- fig, ax = plt.subplots()
- size = 100 #modify this for more or less points on graph
- xdata = range(0, size) #x-axis values
- ydata = [0] * size #y-axis values
- ln, = plt.plot(xdata, ydata, 'ro-')
- #Create, open, set data interval
- temperature = TemperatureSensor()
- temperature.setChannel(0)
- temperature.openWaitForAttachment(1000)
- temperature.setDataInterval(temperature.getMinDataInterval())
- def init():
- ax.set(xlabel='samples', ylabel='temperature (°C)',
- title='Getting Started Kit')
- ax.set_xlim(0, size)
- ax.set_ylim(10, 30) #expected range of temperature
- return ln,
- def update(i, ydata):
- ydata.append(temperature.getTemperature())
- ydata = ydata[-size:]
- ln.set_ydata(ydata)
- return ln,
- ani = FuncAnimation(fig,
- update,
- fargs=(ydata,),
- init_func=init,
- interval=temperature.getDataInterval(),
- blit=True)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement