我有以下代码将在单击 PyQt 中的“开始”按钮后开始:
def Start(self):
import time
import os
import RPi.GPIO as GPIO
import datetime
GPIO.setmode(GPIO.BCM)
DEBUG = 1
os.system('clear')
# SPI port on GPIO
SPICLK = 18
SPIMISO = 23
SPICS = 25
# set up the SPI interface pins
GPIO.setup(SPIMISO, GPIO.IN)
GPIO.setup(SPICLK, GPIO.OUT)
GPIO.setup(SPICS, GPIO.OUT)
GPIO.output(SPICS, True)
GPIO.output(SPICS, False) # bring CS low
while True:
adcout = 0
read_adc = 0
#s=time.clock()
for i in range(25):
GPIO.output(SPICLK, True)
GPIO.output(SPICLK, False)
adcout <<= 1
if (GPIO.input(SPIMISO)==1):
adcout |= 0x1
time.sleep(0.085)
if (GPIO.input(SPIMISO)==0):
read_adc = adcout
millivolts = read_adc * ( 2500.0 /(pow(2,22)))
read_adc = "%d" % read_adc
millivolts = "%d" % millivolts
if DEBUG:
print millivolts, "mV (ADC)"
上面的程序用于 ADC 读取,它会在单击名为“开始”的按钮后启动,如下所示:self.pushButton.clicked.connect( self.Start)
我还有另一个pushButton_2
叫做“停止”,通过点击这个,上面的过程应该停止。请建议,所以我可以做到这一点。