import time
import os
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008
import RPi.GPIO as GPIO
import time
from time import sleep
##BELOW ARE STUFF ASSOCIATED WITH THE PLOTTING
import initExample ## Add path to library (just for examples; you do not need this)
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
#-------------------------------------------#
# Software SPI configuration:
#CLK = 18
#MISO = 23
#MOSI = 24
#CS = 25
#mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
# Hardware SPI configuration:
SPI_PORT = 0
SPI_DEVICE = 0
mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
#mw = QtGui.QMainWindow()
#mw.resize(800,800)
#-------------------------------------------#
win = pg.GraphicsWindow(title="Basic plotting examples")
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: Plotting')
# Enable antialiasing for prettier plots
pg.setConfigOptions(antialias=True)
newArray = []
for x in range(20):
values = [0]*8
#for i in range(8):
#The read_adc function will get the value of the specified channel (0-7).
values[0] = mcp.read_adc(0)
# Print the ADC values.
print('Current value is')
print(values[0])
newArray.append([values[0]])
print(newArray)
time.sleep(0.5)
##ranArray = np.random
ranArray = np.asarray(newArray)
print(ranArray)
p6 = win.addPlot(title="S11")
curve = p6.plot(pen='w')
data = np.asarray(newArray)
##.normal(size=(20,20))
ptr = 0
def update():
global curve, data, ptr, p6
curve.setData(data[ptr%10])
if ptr == 0:
p6.enableAutoRange('xy', False) ## stop auto-scaling after the first data set is plotted
ptr += 1
print(data)
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(1000) #1000 = 1 second
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()