我正在为树莓派开发一个程序。目前,我只是想让程序打印“黄色LED亮”或“红色LED亮”。我对线程是全新的,但是对python却不是。我目前有一些代码写出来,但是我不知道为什么当我运行它时,什么也没有发生,并且程序永远不会终止。如果有人有任何想法,将不胜感激。 我已经在下面发布了代码。 预先感谢。
from threading import Thread
import random
import time
def blinking_LED(n,t):
i = 10
for x in range (n,i):
if (x % 2) == 0:
color = "yellow"
n += 1
else:
color = "red"
n += 1
# output result
if (color == "yellow"):
print ("Yellow LED on")
time.sleep(2)
else:
print ("Red LED on")
time.sleep(2)
#exit function,terminate program
s.quit()
if __name__ == "__main__":
# value to pass into the functions
v = 1
# create threads
t1 = Thread(target=blinking_LED,args=(v,1))
# Start threads
t1.start()
#tell main thread to stay alive until both threads are done
t1.join()