我试图使这些GPIO端口同时打开和关闭,但在RPi上有不同的时间间隔。我可以运行其中的一个循环,它工作,但当我带来线程,它没有。
import RPi.GPIO as GPIO
from time import sleep
import thread
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
def fast():
while True:
GPIO.output(11, True)
sleep(.02)
GPIO.output(11, False)
sleep(.02)
def med():
while True:
GPIO.output(13, True)
sleep(.2)
GPIO.output(13, False)
sleep(.2)
def slow():
while True:
GPIO.output(15, True)
sleep(2)
GPIO.output(15, False)
sleep(2)
thread.start_new_thread(fast,())
thread.start_new_thread(med,())
thread.start_new_thread(slow,())发布于 2014-12-14 23:24:03
这是因为没有主程序/循环。您的代码启动了这些线程,但随后它将结束代码并退出运行python的进程,从而杀死线程。所以,可以在底部添加一个raw_input("Press enter to exit")。
https://stackoverflow.com/questions/27475268
复制相似问题